CNLiveUserUpdateViewController.m
16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
//
// CNLiveUserUpdateViewController.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/25.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNLiveUserUpdateViewController.h"
#import "CNLiveRegisterViewController.h"
#import "CNLiveForgotPasswordViewController.h"
#import "CNLiveLoginInputView.h"
#import "CNLiveThirdLoginView.h"
#import "ZXWUserModel.h"
@interface CNLiveUserUpdateViewController (){
BOOL _hasGetVerification;
}
@property (nonatomic, strong) CNLiveLoginInputView *account;
@property (nonatomic, strong) CNLiveLoginInputView *pwd;
@end
@implementation CNLiveUserUpdateViewController
- (void)viewDidLoad {
[super viewDidLoad];
_hasGetVerification = NO;
[self setUpNavigationBar];
[self setUpSubControllers];
// Do any additional setup after loading the view.
}
#pragma mark - UI
- (void)setUpNavigationBar{
self.navigationController.navigationBar.barTintColor = Color_Blue;
UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
headerButton.layer.cornerRadius = 2.0;
headerButton.layer.masksToBounds = true;
[headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
[headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
self.navigationItem.title = self.navTitle;
}
- (void)setUpSubControllers{
UIButton *sureButton = [[UIButton alloc] init];
sureButton.tag = 10000;
sureButton.layer.cornerRadius = 5.0;
sureButton.layer.masksToBounds = true;
[sureButton addTarget:self action:@selector(clicekdButton:) forControlEvents:UIControlEventTouchUpInside];
[sureButton setTitle:CustomStr(@"Sure") forState:UIControlStateNormal];
[sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
sureButton.titleLabel.font = [UIFont systemFontOfSize:17];
sureButton.backgroundColor = Color_Blue;
[self.view addSubview:sureButton];
if([self.navTitle isEqualToString:CustomStr(@"UpdateNickname")]){
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *name = [userDefaults valueForKey:@"user_name"];
_account = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone_email" placeholder:name&&![name isEqualToString:@""]?name:CustomStr(@"Nickname") type:CNLiveButtonTypeNormal];
_account.textField.text = name&&![name isEqualToString:@""]?name:CustomStr(@"Nickname");
[self.view addSubview:_account];
[_account mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(15);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(0);
make.height.offset(40);
}];
[sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_account.mas_bottom).with.offset(20);
make.left.equalTo(self.view.mas_left).with.offset(10);
make.right.equalTo(self.view.mas_right).with.offset(-10);
make.height.offset(40);
}];
}
else if([self.navTitle isEqualToString:CustomStr(@"UpdateLoginPassword")]){
_account = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_password" placeholder:CustomStr(@"PleaseEnterYourOldLoginPassword") type:CNLiveButtonTypeNormal];
[self.view addSubview:_account];
[_account mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(15);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(0);
make.height.offset(40);
}];
_pwd = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_password" placeholder:CustomStr(@"PleaseEnterYourNewLoginPassword") type:CNLiveButtonTypeTextEntry];
[self.view addSubview:_pwd];
[_pwd mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_account.mas_bottom).with.offset(15);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(0);
make.height.offset(40);
}];
[sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_pwd.mas_bottom).with.offset(20);
make.left.equalTo(self.view.mas_left).with.offset(10);
make.right.equalTo(self.view.mas_right).with.offset(-10);
make.height.offset(40);
}];
}
else if([self.navTitle isEqualToString:CustomStr(@"BindingPhoneNumber")]){
_account = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone_email" placeholder:CustomStr(@"PhoneNumber") type:CNLiveButtonTypeNormal];
[self.view addSubview:_account];
[_account mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(15);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(0);
make.height.offset(40);
}];
if([User_Defaults objectForKey:@"user_phone"] && [User_Defaults objectForKey:@"user_phone"] != nil && ![[User_Defaults objectForKey:@"user_phone"] isEqualToString:@""]){
_account.textField.text = [User_Defaults objectForKey:@"user_phone"];
}
_pwd = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone_message" placeholder:CustomStr(@"Code") type:CNLiveButtonTypeCode];
__weak typeof(self) weakSelf = self;
_pwd.block = ^{
[weakSelf getVerification];
};
[self.view addSubview:_pwd];
[_pwd mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_account.mas_bottom).with.offset(15);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(0);
make.height.offset(40);
}];
[sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_pwd.mas_bottom).with.offset(20);
make.left.equalTo(self.view.mas_left).with.offset(10);
make.right.equalTo(self.view.mas_right).with.offset(-10);
make.height.offset(40);
}];
}
else if([self.navTitle isEqualToString:CustomStr(@"BindingEmail")]){
_account = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_email" placeholder:CustomStr(@"Email") type:CNLiveButtonTypeNormal];
[self.view addSubview:_account];
[_account mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(15);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(0);
make.height.offset(40);
}];
if([User_Defaults objectForKey:@"user_email"] && [User_Defaults objectForKey:@"user_email"] != nil && ![[User_Defaults objectForKey:@"user_email"] isEqualToString:@""]){
_account.textField.text = [User_Defaults objectForKey:@"user_email"];
}
[sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_account.mas_bottom).with.offset(20);
make.left.equalTo(self.view.mas_left).with.offset(10);
make.right.equalTo(self.view.mas_right).with.offset(-10);
make.height.offset(40);
}];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - Action
- (void)allResignFirstResponder{
[_account.textField resignFirstResponder];
[_pwd.textField resignFirstResponder];
}
- (void)clicekdButton:(UIButton *)btn{
btn.userInteractionEnabled = NO;
[self updateRequest:btn];
}
- (void)updateRequest:(UIButton *)btn{
[self allResignFirstResponder];
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
btn.userInteractionEnabled = YES;
return;
}
ZXWUserInformation *share = [ZXWUserInformation shareZXWUserInformation];
NSString *uid = share.model.uid;
if([self.navTitle isEqualToString:CustomStr(@"UpdateNickname")]){
#pragma mark - CNLiveUserSystemSDK 修改昵称
NSString *unickname = share.model.nickname;
if([unickname isEqualToString:_account.textField.text]){
btn.userInteractionEnabled = YES;
[self goBack];
return;
}
[AlertViewTool showHUDView];
[CNLiveUserSystemCenter modifyUserInfoType:UserInfoTypeNickName uid:uid modifyInfo:_account.textField.text success:^(NSDictionary *result) {
[AlertViewTool hideHUDView];
if ([result[@"errorCode"] integerValue] == 0) {
share.model.nickname = self->_account.textField.text;
[share saveUser_name:self->_account.textField.text];
[[NSNotificationCenter defaultCenter] postNotificationName:LoginSuccessful object:nil];
[AlertViewTool showHUDViewText:CustomStr(@"UpdateNicknameSuccess") block:^{
btn.userInteractionEnabled = YES;
[self goBack];
}];
} else {
[AlertViewTool showHUDViewText:CustomStr(@"UpdateNicknameFailure") block:^{
btn.userInteractionEnabled = YES;
[self goBack];
}];
}
} failure:^(NSDictionary *errorDic) {
btn.userInteractionEnabled = YES;
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:errorDic[@"errorMessage"]];
}];
}
else if([self.navTitle isEqualToString:CustomStr(@"UpdateLoginPassword")]){
#pragma mark - CNLiveUserSystemSDK 修改密码
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_pwd"];
if (![_account.textField.text isEqualToString:password]) {
[AlertViewTool showHUDViewText:CustomStr(@"OldPasswordError")];
btn.userInteractionEnabled = YES;
return;
}
if(![_pwd.textField.text isValidPassWordLegal]){
[AlertViewTool showHUDViewText:CustomStr(@"PasswordError")];
btn.userInteractionEnabled = YES;
return;
}
[AlertViewTool showHUDView];
[CNLiveUserSystemCenter oldPwdChangePasswordWithUid:uid pwd:password newPwd:_pwd.textField.text success:^(id result) {
[AlertViewTool hideHUDView];
if ([result[@"errorCode"] integerValue] == 0) {
[[ZXWUserInformation shareZXWUserInformation] loginOut];
[AlertViewTool showHUDViewText:CustomStr(@"UpdatePasswordSuccess") block:^{
btn.userInteractionEnabled = YES;
[self.navigationController popToViewController:self.navigationController.childViewControllers[0] animated:YES];
}];
} else {
[AlertViewTool showHUDViewText:CustomStr(@"UpdatePasswordFailure") block:^{
btn.userInteractionEnabled = YES;
}];
}
} failure:^(NSDictionary *errorDic) {
btn.userInteractionEnabled = YES;
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:errorDic[@"errorMessage"]];
}];
}
else if([self.navTitle isEqualToString:CustomStr(@"BindingPhoneNumber")]){
#pragma mark - CNLiveUserSystemSDK 绑定手机号
if(![_account.textField.text isValidMobile]){
[AlertViewTool showHUDViewText:CustomStr(@"PhoneNumberError")];
btn.userInteractionEnabled = YES;
return;
}
if (!_hasGetVerification) {
[AlertViewTool showHUDViewText:CustomStr(@"YouHaveNotGottenTheCaptchaYet")];
btn.userInteractionEnabled = YES;
return;
}
if(![_pwd.textField.text isValidCode]){
[AlertViewTool showHUDViewText:CustomStr(@"CodeError")];
btn.userInteractionEnabled = YES;
return;
}
[AlertViewTool showHUDView];
[CNLiveUserSystemCenter updateMobileWithUid:uid mobile:_account.textField.text verificationCode:_pwd.textField.text success:^(id result) {
[AlertViewTool hideHUDView];
if ([result[@"errorCode"] integerValue] == 0) {
share.model.mobile = self->_account.textField.text;
[share saveUser_phone:self->_account.textField.text];
[AlertViewTool showHUDViewText:CustomStr(@"BindPhoneNumberSuccess") block:^{
btn.userInteractionEnabled = YES;
[self goBack];
}];
} else {
[AlertViewTool showHUDViewText:CustomStr(@"BindPhoneNumberFailure") block:^{
btn.userInteractionEnabled = YES;
[self goBack];
}];
}
} failure:^(NSDictionary *errorDic) {
btn.userInteractionEnabled = YES;
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:errorDic[@"errorMessage"]];
}];
}
else if([self.navTitle isEqualToString:CustomStr(@"BindingEmail")]){
#pragma mark - CNLiveUserSystemSDK 绑定邮箱
if(![_account.textField.text isValidEmail]){
[AlertViewTool showHUDViewText:CustomStr(@"EmailError")];
btn.userInteractionEnabled = YES;
return;
}
[AlertViewTool showHUDView];
[CNLiveUserSystemCenter modifyUserInfoType:UserInfoTypeEmail uid:uid modifyInfo:_account.textField.text success:^(NSDictionary *result) {
[AlertViewTool hideHUDView];
if ([result[@"errorCode"] integerValue] == 0) {
[share saveUser_email:self->_account.textField.text];
[AlertViewTool showHUDViewText:CustomStr(@"BindEmailSuccess") block:^{
btn.userInteractionEnabled = YES;
[self goBack];
}];
} else {
[AlertViewTool showHUDViewText:CustomStr(@"BindEmailFailure") block:^{
btn.userInteractionEnabled = YES;
[self goBack];
}];
}
} failure:^(NSDictionary *errorDic) {
btn.userInteractionEnabled = YES;
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:errorDic[@"errorMessage"]];
}];
}
}
#pragma mark - CNLiveUserSystemSDK 获取验证码
- (void)getVerification{
[self allResignFirstResponder];
if(![_account.textField.text isValidMobile]){
[AlertViewTool showHUDViewText:CustomStr(@"PhoneNumberError")];
return;
}
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
return;
}
[AlertViewTool showHUDView];
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRegister mobile:_account.textField.text success:^(NSDictionary *result) {
[AlertViewTool hideHUDView];
if ([result[@"errorCode"] integerValue] == 0) {
self->_hasGetVerification = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:GetCodeSuccessful object:nil];
[AlertViewTool showHUDViewText:CustomStr(@"CodeSendingSuccessful")];
} else {
[AlertViewTool showHUDViewText:CustomStr(@"CodeSendingFailed")];
}
} failure:^(NSDictionary *errorDic) {
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:errorDic[@"errorMessage"]];
}];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end