RegisterViewController.m
9.54 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
//
// ResgisterViewController.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/14.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "RegisterViewController.h"
#import "RegistBasicInformationView.h"
@interface RegisterViewController ()
@property (nonatomic, strong)RegistBasicInformationView *registBasicInformationView;
@property (nonatomic, strong)UIButton *verificationBtn;
@property (nonatomic, strong)UIButton *loginBtn;
@end
@implementation RegisterViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([_type isEqualToString:@"register"]) {
self.title = @"注册";
} else if ([_type isEqualToString:@"quicklyLogin"]) {
self.title = @"快捷登录";
} else {
self.title = @"修改密码";
}
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.registBasicInformationView];
[self.view addSubview:self.verificationBtn];
[self.view addSubview:self.loginBtn];
}
#pragma mark - action
- (void)verificationBtnAction
{
[self startTimer];
if ([_type isEqualToString:@"register"]) {
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRegister mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[Tools toast:result[@"errorMessage"]];
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
}];
} else if ([_type isEqualToString:@"quicklyLogin"]) {
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeShortcutLogin mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[Tools toast:result[@"errorMessage"]];
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
}];
} else {
[CNLiveUserSystemCenter verificationCodeType:VerificationCodeTypeRetrievePassword mobile:_registBasicInformationView.phoneTF.text success:^(id result) {
[Tools toast:result[@"errorMessage"]];
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
}];
}
}
- (void)loginBtnAction
{
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD show];
if ([_type isEqualToString:@"register"]) {
[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"]) {
[Tools setUserLogin:YES];
[SVProgressHUD showSuccessWithStatus:@"成功"];
[UserInfoSava saveUserinfoDic:result[@"data"]];
[self.navigationController popToRootViewControllerAnimated:YES];
} else {
[Tools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
[SVProgressHUD dismiss];
}];
} else if ([_type isEqualToString:@"quicklyLogin"]) {
[CNLiveUserSystemCenter shortcutLoginWithUserName:_registBasicInformationView.phoneTF.text verificationCode:_registBasicInformationView.verificationTF.text frmId:nil success:^(id result) {
if ([[result allKeys] containsObject:@"errorCode"] && [result[@"errorCode"] isEqualToString:@"0"]) {
[Tools setUserLogin:YES];
[SVProgressHUD showSuccessWithStatus:@"成功"];
[UserInfoSava saveUserinfoDic:result[@"data"]];
[self.navigationController popToRootViewControllerAnimated:YES];
} else {
[Tools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
[SVProgressHUD dismiss];
}];
} else {
[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 popToRootViewControllerAnimated:YES];
} else {
[Tools toast:result[@"errorMessage"]];
[SVProgressHUD dismiss];
}
} failure:^(NSError *error) {
[Tools toast:error.localizedDescription];
[SVProgressHUD dismiss];
}];
}
}
- (void)startTimer
{
__block int timeout = 60; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _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.userInteractionEnabled = YES;
});
}else{
// int minutes = timeout / 60;
int seconds = timeout % 60;
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[self.verificationBtn setTitle:[NSString stringWithFormat:@"%@秒",strTime] forState:UIControlStateNormal];
self.verificationBtn.userInteractionEnabled = NO;
});
timeout--;
}
});
dispatch_resume(_timer);
}
#pragma mark - getter
- (RegistBasicInformationView *)registBasicInformationView
{
if (!_registBasicInformationView) {
if ([_type isEqualToString:@"quicklyLogin"]) {
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 70, KScreenWidth, 171) hasPwd:NO isPhone:YES];
} else if ([_type isEqualToString:@"register"]) {
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 70, KScreenWidth, 171) hasPwd:YES isPhone:NO];
} else {
_registBasicInformationView = [[RegistBasicInformationView alloc] initWithFrame:CGRectMake(0, 70, KScreenWidth, 171) hasPwd:YES isPhone:YES];
}
}
return _registBasicInformationView;
}
- (UIButton *)verificationBtn
{
if (!_verificationBtn) {
_verificationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_verificationBtn setFrame:CGRectMake(KScreenWidth - 105, 80, 95, 37)];
_verificationBtn.backgroundColor = [UIColor orangeColor];
_verificationBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[_verificationBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
[_verificationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_verificationBtn addTarget:self action:@selector(verificationBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _verificationBtn;
}
- (UIButton *)loginBtn
{
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_loginBtn.backgroundColor = [UIColor orangeColor];
[_loginBtn setFrame:CGRectMake(10, 280, KScreenWidth - 20, 40)];
_loginBtn.layer.cornerRadius = 20;
_loginBtn.layer.masksToBounds = YES;
if ([_type isEqualToString:@"register"]) {
[_loginBtn setTitle:@"注 册" forState:UIControlStateNormal];
} else if ([_type isEqualToString:@"quicklyLogin"]) {
[_loginBtn setTitle:@"快捷登录" forState:UIControlStateNormal];
} else {
[_loginBtn setTitle:@"确 认" forState:UIControlStateNormal];
}
[_loginBtn addTarget:self action:@selector(loginBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _loginBtn;
}
- (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.
}
*/
@end