RegisterCommonController.m
17.4 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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
//
// RegisterCommonController.m
// LiveVideoCloud
//
// Created by cnlive on 17/4/11.
// Copyright © 2017年 CNLive. All rights reserved.
//
#import "RegisterCommonController.h"
#import "RegistBasicInformationView.h"
#import "LVCWebViewController.h"
@interface RegisterCommonController ()
{
dispatch_source_t _timer;
}
@property (nonatomic, strong)RegistBasicInformationView *registBasicInformationView;
@property (nonatomic, strong)UIButton *verificationBtn;
@property (nonatomic, strong)UIButton *loginBtn;
@property (nonatomic, strong)UIButton *readBtn;
@property (nonatomic, strong)UIButton *userServiceTermsBtn;
@end
@implementation RegisterCommonController
- (void)viewDidLoad {
[super viewDidLoad];
switch (_type) {
case RegisterTypeRegist:
{
self.title = @"注 册";
}
break;
case RegisterTypeMessageQuicklyLogin:
{
self.title = @"快捷登录";
}
break;
case RegisterTypeMessageChangeMobile:
{
self.title = @"修改手机号";
}
break;
case RegisterTypeChangePassword:
{
self.title = @"修改密码";
}
break;
default:
break;
}
// self.view.backgroundColor = CommonBgColor;
[self.view addSubview:self.registBasicInformationView];
[self.view addSubview:self.verificationBtn];
[self.view addSubview:self.loginBtn];
}
#pragma mark - action
-(void)onBackAction
{
[SVProgressHUD dismiss];
// if (_type == RegisterTypeRegist) {
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"注册即送520个中国币,你确定要放弃了吗?" preferredStyle:UIAlertControllerStyleAlert];
// UIAlertAction *cancelAlertAction = [UIAlertAction actionWithTitle:@"放弃" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// [self.navigationController popViewControllerAnimated:YES];
// }];
// UIAlertAction *okAlertAction = [UIAlertAction actionWithTitle:@"追求财富" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//
// }];
// [alertController addAction:cancelAlertAction];
// [alertController addAction:okAlertAction];
// [self presentViewController:alertController animated:YES completion:nil];
//
// }else
// {
[self.navigationController popViewControllerAnimated:YES];
// [super onBackAction];
// }
}
- (void)verificationBtnAction
{
if ([Tools isMobileNumber:self.registBasicInformationView.phoneTF.text]) {
[self startTimer];
switch (_type) {
case RegisterTypeRegist:
{
[self.view addSubview:self.readBtn];
[self.view addSubview:self.userServiceTermsBtn];
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRegister mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[UserTools setUserLogin:YES];
[UserTools toast:result[@"errorMessage"]];
[self cancelVerBtnChange];
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
[self cancelVerBtnChange];
}];
}
break;
case RegisterTypeMessageQuicklyLogin:
{
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeShortcutLogin mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[UserTools toast:result[@"errorMessage"]];
[self cancelVerBtnChange];
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
[self cancelVerBtnChange];
}];
}
break;
case RegisterTypeMessageChangeMobile:
{
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRegister mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[UserTools toast:result[@"errorMessage"]];
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
}];
}
break;
case RegisterTypeChangePassword:
{
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRetrievePassword mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[UserTools toast:result[@"errorMessage"]];
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
}];
}
break;
default:
break;
}
}
}
- (void)readBtnAction:(UIButton *)button
{
button.selected = !button.selected;
}
- (void)userServiceTermsBtnAction:(UIButton *)button
{
LVCWebViewController *VC = [[LVCWebViewController alloc] init];
VC.url = uploadServiceProtocol;
VC.title = @"视讯中国充值协议";
[self.navigationController pushViewController:VC animated:YES];
}
- (void)loginBtnAction
{
switch (_type) {
case RegisterTypeRegist:
{
if (![Tools isMobileNumber:self.registBasicInformationView.phoneTF.text]) {
[Tools showHUDInView:self.view withString:@"请输入正确的手机号码" autoHide:YES];
return;
}
else if (self.registBasicInformationView.verificationTF.text == nil || [self.registBasicInformationView.verificationTF.text isEqualToString:@""]) {
[Tools showHUDInView:self.view withString:@"请输入验证码" autoHide:YES];
return;
}
else if (self.registBasicInformationView.setPwdTF.text == nil || [self.registBasicInformationView.setPwdTF.text isEqualToString:@""]) {
[Tools showHUDInView:self.view withString:@"请设置密码" autoHide:YES];
return;
}
else if (!self.readBtn.selected) {
[Tools showHUDInView:self.view withString:@"请阅读并同意《用户服务条款》" autoHide:YES];
}
else{
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD showWithStatus:@"正在注册..."];
[CNLiveUserSystemCenter registerWithUserName:_registBasicInformationView.phoneTF.text password:_registBasicInformationView.setPwdTF.text verificationCode:_registBasicInformationView.verificationTF.text invitationCode:nil frmId:nil success:^(id result) {
if ([[result allKeys] containsObject:@"errorCode"] && [result[@"errorCode"] isEqualToString:@"0"]) {
[SVProgressHUD showSuccessWithStatus:@"成功"];
[UserTools saveUserinfoDic:result[@"data"]];
[self.navigationController popToRootViewControllerAnimated:YES];
} else {
[UserTools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
[SVProgressHUD dismiss];
}];
}
break;
case RegisterTypeMessageQuicklyLogin:
{
[CNLiveUserSystemCenter shortcutLoginWithUserName:_registBasicInformationView.phoneTF.text verificationCode:_registBasicInformationView.verificationTF.text frmId:nil success:^(id result) {
if ([[result allKeys] containsObject:@"errorCode"] && [result[@"errorCode"] isEqualToString:@"0"]) {
[SVProgressHUD setMinimumDismissTimeInterval:2.0];
[SVProgressHUD showSuccessWithStatus:@"成功"];
[UserTools saveUserinfoDic:result[@"data"]];
[self.navigationController popToRootViewControllerAnimated:YES];
} else {
[UserTools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
[SVProgressHUD dismiss];
}];
}
break;
case RegisterTypeMessageChangeMobile:
{
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRegister mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[SVProgressHUD showSuccessWithStatus:@"成功"];
[UserTools saveUserinfoDic:result[@"data"]];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
[SVProgressHUD dismiss];
}];
}
break;
case RegisterTypeChangePassword:
{
[CNLiveUserSystemCenter changePasswordWithMobile:_registBasicInformationView.phoneTF.text verificationCode:_registBasicInformationView.verificationTF.text newPassword:_registBasicInformationView.setPwdTF.text success:^(id result) {
if ([[result allKeys] containsObject:@"errorCode"] && [result[@"errorCode"] isEqualToString:@"0"]) {
[SVProgressHUD showSuccessWithStatus:@"密码修改成功"];
[self.navigationController popViewControllerAnimated:YES];
} else {
[UserTools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSDictionary *errorDic) {
[UserTools toast:errorDic[@"errorMessage"]];
[SVProgressHUD dismiss];
}];
}
break;
default:
break;
}
}
}
//恢复原状
- (void)cancelVerBtnChange
{
dispatch_source_cancel(_timer);//取消定时器
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示
[self.verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
self.verificationBtn.userInteractionEnabled = YES;
[UIView animateWithDuration:0.25 animations:^{
self.verificationBtn.left = SCREEN_W - 166 / 2;
self.verificationBtn.width = 73;
}];
});
}
- (void)startTimer
{
__block int timeout = 60; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[self.verificationBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
[self.verificationBtn setFrame:CGRectMake(SCREEN_W - 166 / 2, 23 , 146 / 2, 25)];
self.verificationBtn.userInteractionEnabled = YES;
});
}else{
// int minutes = timeout / 60;
int seconds = timeout % 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
if(seconds == 0)strTime = [NSString stringWithFormat:@"%d",timeout];
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[self.verificationBtn setTitle:[NSString stringWithFormat:@"%@秒重新获取验证码",strTime] forState:UIControlStateNormal];
CGSize size = [self.verificationBtn.titleLabel labelSize];
self.verificationBtn.userInteractionEnabled = NO;
[UIView animateWithDuration:0.25 animations:^{
self.verificationBtn.left = SCREEN_W - 20 - size.width - 5;
self.verificationBtn.width = size.width + 10;
}];
});
timeout--;
}
});
dispatch_resume(_timer);
}
#pragma mark - getter
- (RegistBasicInformationView *)registBasicInformationView
{
if (!_registBasicInformationView)
{
switch (_type) {
case RegisterTypeRegist:
{
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 7, KScreenWidth, 173) hasPwd:YES isPhone:YES];
}
break;
case RegisterTypeMessageQuicklyLogin:
{
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 7, KScreenWidth, 57*2+1) hasPwd:NO isPhone:YES];
}
break;
case RegisterTypeChangePassword:
{
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 7, KScreenWidth, 171+2) hasPwd:YES isPhone:YES];
}
break;
default:
break;
}
}
return _registBasicInformationView;
}
- (UIButton *)verificationBtn
{
if (!_verificationBtn) {
_verificationBtn = [UIButton buttonWithTitle:@"获取验证码" titleColor:[UIColor blackColorCNLive] labelFontSize:12 cornerRadius:25.0 * 0.5 borderWidth:1.0f borderColor:[UIColor blackColorCNLive]];
[_verificationBtn setFrame:CGRectMake(SCREEN_W - 166 / 2, 7+(57-25)*0.5 , 146 / 2, 25)];
[_verificationBtn addTarget:self action:@selector(verificationBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _verificationBtn;
}
- (UIButton *)loginBtn
{
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithTitle:@"" titleColor:[UIColor blackColorCNLive] cornerRadius:20 borderWidth:1.0f borderColor:[UIColor blackColorCNLive] backgroundColor:[UIColor yellowColorCNLive]];
[_loginBtn setFrame:CGRectMake(10, 280, KScreenWidth - 20, 40)];
switch (_type) {
case RegisterTypeRegist:
{
[_loginBtn setTitle:@"注 册" forState:UIControlStateNormal];
}
break;
case RegisterTypeMessageQuicklyLogin:
{
[_loginBtn setTitle:@"快捷登录" forState:UIControlStateNormal];
}
break;
case RegisterTypeChangePassword:
{
[_loginBtn setTitle:@"确 认" forState:UIControlStateNormal];
}
break;
default:
break;
}
[_loginBtn addTarget:self action:@selector(loginBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _loginBtn;
}
- (UIButton *)readBtn
{
if (!_readBtn) {
_readBtn = [UIButton buttonWithBackgroundImageNormal:[UIImage imageNamed:@"woyiyuedu_default"] backgroundImageSelected:[UIImage imageNamed:@"woyiyuedu_focused"]];
[_readBtn setFrame:CGRectMake(9, _registBasicInformationView.bottom + 11, 30, 30)];
[_readBtn addTarget:self action:@selector(readBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _readBtn;
}
- (UIButton *)userServiceTermsBtn
{
if (!_userServiceTermsBtn) {
_userServiceTermsBtn = [UIButton buttonWithTitle:@"我已阅读并同意《用户服务条款》" titleColor:[UIColor clearColor] labelFontSize:15];
CGSize size = [_userServiceTermsBtn.titleLabel labelSize];
_userServiceTermsBtn.width = size.width;
_userServiceTermsBtn.height = size.height;
_userServiceTermsBtn.centerY = self.readBtn.centerY;
_userServiceTermsBtn.left = self.readBtn.right + 9;
[_userServiceTermsBtn setTitleColor:[UIColor grayColorCNLive] forState:UIControlStateNormal];
[_userServiceTermsBtn addTarget:self action:@selector(userServiceTermsBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _userServiceTermsBtn;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
@end