Skip to content

Commit 323c8e3

Browse files
committed
修改手机号码 - 支持全球
1 parent fdc9812 commit 323c8e3

File tree

4 files changed

+58
-36
lines changed

4 files changed

+58
-36
lines changed

Coding_iOS/Controllers/MeSetting/SettingPhoneViewController.m

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
#import "TPKeyboardAvoidingTableView.h"
1212
#import "Coding_NetAPIManager.h"
1313
#import "Login.h"
14+
#import "CountryCodeListViewController.h"
1415

1516
@interface SettingPhoneViewController ()<UITableViewDataSource, UITableViewDelegate>
1617
@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView;
17-
@property (strong, nonatomic) NSString *phone, *code;
18+
@property (strong, nonatomic) NSString *phone, *code, *phone_country_code, *country, *verifyStr;
1819
@property (strong, nonatomic) NSString *phoneCodeCellIdentifier;
19-
20+
@property (assign, nonatomic) VerifyType verifyType;
2021
@end
2122

2223
@implementation SettingPhoneViewController
@@ -26,6 +27,8 @@ - (void)viewDidLoad {
2627
// Do any additional setup after loading the view.
2728
self.title = @"绑定手机号码";
2829
self.phone = [Login curLoginUser].phone;
30+
self.country = [Login curLoginUser].country;
31+
self.phone_country_code = [Login curLoginUser].phone_country_code;
2932

3033
// 添加myTableView
3134
self.phoneCodeCellIdentifier = [Input_OnlyText_Cell randomCellIdentifierOfPhoneCodeType];
@@ -35,7 +38,9 @@ - (void)viewDidLoad {
3538
tableView.dataSource = self;
3639
tableView.delegate = self;
3740
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
41+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Phone];
3842
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Text];
43+
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:kCellIdentifier_Input_OnlyText_Cell_Password];
3944
[tableView registerClass:[Input_OnlyText_Cell class] forCellReuseIdentifier:self.phoneCodeCellIdentifier];
4045
[self.view addSubview:tableView];
4146
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -45,14 +50,25 @@ - (void)viewDidLoad {
4550
});
4651
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(doneBtnClicked:)];
4752

53+
self.verifyType = VerifyTypePassword;
54+
[[Coding_NetAPIManager sharedManager] request_VerifyTypeWithBlock:^(VerifyType type, NSError *error) {
55+
if (!error) {
56+
self.verifyType = type;
57+
[self.myTableView reloadData];
58+
}
59+
}];
4860
}
4961
#pragma mark TableM
5062

5163
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
52-
return 2;
64+
return 3;
5365
}
5466
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
55-
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:indexPath.row == 0? self.phoneCodeCellIdentifier: kCellIdentifier_Input_OnlyText_Cell_Text forIndexPath:indexPath];
67+
NSString *identifier = (indexPath.row == 0? kCellIdentifier_Input_OnlyText_Cell_Phone:
68+
indexPath.row == 1? self.phoneCodeCellIdentifier:
69+
_verifyType == VerifyTypePassword? kCellIdentifier_Input_OnlyText_Cell_Password:
70+
kCellIdentifier_Input_OnlyText_Cell_Text);
71+
Input_OnlyText_Cell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
5672

5773
__weak typeof(self) weakSelf = self;
5874
if (indexPath.row == 0) {
@@ -61,15 +77,24 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
6177
cell.textValueChangedBlock = ^(NSString *valueStr){
6278
weakSelf.phone = valueStr;
6379
};
64-
cell.phoneCodeBtnClckedBlock = ^(PhoneCodeButton *btn){
65-
[weakSelf phoneCodeBtnClicked:btn];
80+
cell.countryCodeL.text = _phone_country_code;
81+
cell.countryCodeBtnClickedBlock = ^(){
82+
[weakSelf goToCountryCodeVC];
6683
};
67-
}else{
84+
}else if (indexPath.row == 1){
6885
cell.textField.keyboardType = UIKeyboardTypeNumberPad;
6986
[cell setPlaceholder:@" 手机验证码" value:self.code];
7087
cell.textValueChangedBlock = ^(NSString *valueStr){
7188
weakSelf.code = valueStr;
7289
};
90+
cell.phoneCodeBtnClckedBlock = ^(PhoneCodeButton *btn){
91+
[weakSelf phoneCodeBtnClicked:btn];
92+
};
93+
}else{
94+
[cell setPlaceholder:_verifyType == VerifyTypePassword? @" 输入密码": @" 输入两步验证码" value:_verifyStr];
95+
cell.textValueChangedBlock = ^(NSString *valueStr){
96+
weakSelf.verifyStr = valueStr;
97+
};
7398
}
7499
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
75100
return cell;
@@ -99,7 +124,7 @@ - (void)phoneCodeBtnClicked:(PhoneCodeButton *)sender{
99124
return;
100125
}
101126
sender.enabled = NO;
102-
[[Coding_NetAPIManager sharedManager] request_GeneratePhoneCodeToResetPhone:_phone block:^(id data, NSError *error) {
127+
[[Coding_NetAPIManager sharedManager] request_GeneratePhoneCodeToResetPhone:_phone phoneCountryCode:_phone_country_code block:^(id data, NSError *error) {
103128
if (data) {
104129
[NSObject showHudTipStr:@"验证码发送成功"];
105130
[sender startUpTimer];
@@ -116,19 +141,36 @@ - (void)doneBtnClicked:(id)sender{
116141
tipStr = @"手机号码格式有误";
117142
}else if (_code.length <= 0){
118143
tipStr = @"请填写手机验证码";
144+
}else if (_verifyStr.length <= 0){
145+
tipStr = _verifyType == VerifyTypePassword? @"请填写密码": @"请填写两步验证码";
119146
}
120147
if (tipStr.length > 0) {
121148
[NSObject showHudTipStr:tipStr];
122149
return;
123150
}
151+
NSMutableDictionary *params = @{@"phone": _phone,
152+
@"code": _code,
153+
@"phoneCountryCode": _phone_country_code,
154+
@"two_factor_code": _verifyType == VerifyTypePassword? [_verifyStr sha1Str]: _verifyStr}.mutableCopy;
124155
__weak typeof(self) weakSelf = self;
125-
[[Coding_NetAPIManager sharedManager] request_ResetPhone:_phone code:_code andBlock:^(id data, NSError *error) {
126-
weakSelf.navigationItem.rightBarButtonItem.enabled = YES;
156+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/account/phone/change" withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
127157
if (data) {
128158
[NSObject showHudTipStr:@"手机号码绑定成功"];
129159
[weakSelf.navigationController popViewControllerAnimated:YES];
130160
}
131161
}];
132162
}
133163

164+
#pragma mark - VC
165+
- (void)goToCountryCodeVC{
166+
__weak typeof(self) weakSelf = self;
167+
CountryCodeListViewController *vc = [CountryCodeListViewController new];
168+
vc.selectedBlock = ^(NSDictionary *countryCodeDict){
169+
weakSelf.country = countryCodeDict[@"iso_code"];
170+
weakSelf.phone_country_code = [NSString stringWithFormat:@"+%@", countryCodeDict[@"country_code"]];
171+
[weakSelf.myTableView reloadData];
172+
};
173+
[self.navigationController pushViewController:vc animated:YES];
174+
}
175+
134176
@end

Coding_iOS/Models/User.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@interface User : NSObject
1212
@property (readwrite, nonatomic, strong) NSString *avatar, *name, *global_key, *path, *slogan, *company, *tags_str, *tags, *location, *job_str, *job, *email, *birthday, *pinyinName;
13-
@property (readwrite, nonatomic, strong) NSString *curPassword, *resetPassword, *resetPasswordConfirm, *phone, *introduction;
13+
@property (readwrite, nonatomic, strong) NSString *curPassword, *resetPassword, *resetPasswordConfirm, *phone, *introduction, *phone_country_code, *country;
1414

1515
@property (readwrite, nonatomic, strong) NSNumber *id, *sex, *follow, *followed, *fans_count, *follows_count, *tweets_count, *status, *points_left, *email_validation, *is_phone_validated;
1616
@property (readwrite, nonatomic, strong) NSDate *created_at, *last_logined_at, *last_activity_at, *updated_at;

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ typedef NS_ENUM(NSInteger, PurposeType) {
205205
- (void)request_UserJobArrayWithBlock:(void (^)(id data, NSError *error))block;
206206
- (void)request_UserTagArrayWithBlock:(void (^)(id data, NSError *error))block;
207207
- (void)request_UpdateUserInfo_WithObj:(User *)curUser andBlock:(void (^)(id data, NSError *error))block;
208-
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone block:(void (^)(id data, NSError *error))block;
209-
- (void)request_ResetPhone:(NSString *)phone code:(NSString *)code andBlock:(void (^)(id data, NSError *error))block;
208+
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone phoneCountryCode:(NSString *)phoneCountryCode block:(void (^)(id data, NSError *error))block;
210209
- (void)request_PointRecords:(PointRecords *)records andBlock:(void (^)(id data, NSError *error))block;
211210
- (void)request_RewardToTweet:(NSString *)tweet_id encodedPassword:(NSString *)encodedPassword andBlock:(void (^)(id data, NSError *error))block;
212211

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,36 +2063,17 @@ - (void)request_UpdateUserInfo_WithObj:(User *)curUser andBlock:(void (^)(id dat
20632063
}];
20642064
}
20652065

2066-
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone block:(void (^)(id data, NSError *error))block{
2067-
NSString *path = @"api/user/generate_phone_code";
2068-
NSDictionary *params = @{@"phone": phone};
2066+
- (void)request_GeneratePhoneCodeToResetPhone:(NSString *)phone phoneCountryCode:(NSString *)phoneCountryCode block:(void (^)(id data, NSError *error))block{
2067+
NSString *path = @"api/account/phone/change/code";
2068+
NSDictionary *params = @{@"phone": phone,
2069+
@"phoneCountryCode": phoneCountryCode};
20692070
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
20702071
if (data) {
20712072
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"生成手机验证码_绑定手机号"];
20722073
}
20732074
block(data, error);
20742075
}];
20752076
}
2076-
- (void)request_ResetPhone:(NSString *)phone code:(NSString *)code andBlock:(void (^)(id data, NSError *error))block{
2077-
NSString *path = @"api/user/updateInfo";
2078-
NSMutableDictionary *params = [[Login curLoginUser] toUpdateInfoParams].mutableCopy;
2079-
params[@"phone"] = phone;
2080-
params[@"code"] = code;
2081-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Post andBlock:^(id data, NSError *error) {
2082-
if (data) {
2083-
[MobClick event:kUmeng_Event_Request_ActionOfServer label:@"个人信息_修改手机号码"];
2084-
2085-
id resultData = [data valueForKeyPath:@"data"];
2086-
User *user = [NSObject objectOfClass:@"User" fromJSON:resultData];
2087-
if (user) {
2088-
[Login doLogin:resultData];
2089-
}
2090-
block(user, nil);
2091-
}else{
2092-
block(nil, error);
2093-
}
2094-
}];
2095-
}
20962077

20972078
- (void)request_PointRecords:(PointRecords *)records andBlock:(void (^)(id data, NSError *error))block{
20982079
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[records toPath] withParams:[records toParams] withMethodType:Get andBlock:^(id data, NSError *error) {

0 commit comments

Comments
 (0)