LoginViewController.m
14.2 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
//
// LoginViewController.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/14.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "LoginViewController.h"
#import "IdAndPwdView.h"
#import "RegisterViewController.h"
#import "CNLiveThirdLoginManager.h"
#define SpaceWidth (KScreenWidth-80*3)/4
@interface LoginViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) IdAndPwdView *idAndPwdView;
@property (nonatomic, strong) UIButton *loginBtn;
@property (nonatomic, strong) UIButton *messageLoginBtn;
@property (nonatomic, strong) UIButton *registBtn;
@property (nonatomic, strong) UIButton *weChatBtn;
@property (nonatomic, strong) UIButton *sinaBtn;
@property (nonatomic, strong) UIButton *qqBtn;
@property (nonatomic, strong) UILabel *thirdpartyLoginLbl;
@property (nonatomic, strong) UIButton *checkThirdBtn;
@property (nonatomic, strong) UIButton *bindMobileBtn;
@property (nonatomic ,strong) UITextField *verificationCodeTF;
@property (nonatomic ,strong) NSDictionary *dic;
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"登录";
self.view.backgroundColor = [UIColor whiteColor];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
backItem.title = @"back";
self.navigationItem.backBarButtonItem = backItem;
[self.view addSubview:self.idAndPwdView];
[self.view addSubview:self.loginBtn];
[self.view addSubview:self.messageLoginBtn];
[self.view addSubview:self.weChatBtn];
[self.view addSubview:self.sinaBtn];
[self.view addSubview:self.qqBtn];
[self.view addSubview:self.thirdpartyLoginLbl];
[self.view addSubview:self.checkThirdBtn];
[self.view addSubview:self.bindMobileBtn];
[self.view addSubview:self.verificationCodeTF];
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.registBtn];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess:) name:ThirdLoginSuccess object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginFailure) name:ThirdLoginFailure object:nil];
}
#pragma mark - action
- (void)loginBtnAction
{
NSDictionary *dic = self.dic;
if (dic) {//三方强制绑定手机号登录
[CNLiveUserSystemCenter thirdPartyBindMobileLoginWithThirdPartyPlatType:[dic objectForKey:@"platType"] thirdPartyId:dic[@"partyId"] nickName:@"testNickName" gender:[dic objectForKey:@"gender"] location:[dic objectForKey:@"location"] faceUrl:[dic objectForKey:@"faceUrl"] mobile:[dic objectForKey:@"mobile"] verificationCode:self.verificationCodeTF.text pawd:_idAndPwdView.pwdTF.text frmId:@"" success:^(id result) {
NSLog(@"BindMobile 登录------%@",result);
[UserInfoSava saveUserinfoDic:result[@"data"]];
[Tools setUserLogin:YES];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSDictionary *errorDic) {
NSLog(@"BindMobile 登录------%@",errorDic);
}];
}else
{//普通登录或三方验证登录
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD show];
[CNLiveUserSystemCenter loginWithUserName:_idAndPwdView.idTF.text password:_idAndPwdView.pwdTF.text frmId:nil success:^(id result) {
NSLog(@"登录 success------------%@",result);
[SVProgressHUD showSuccessWithStatus:@"登录成功"];
[UserInfoSava saveUserinfoDic:result[@"data"]];
[Tools setUserLogin:YES];
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSDictionary *errorDic) {
[Tools toast:[NSString stringWithFormat:@"errorCode : %@ \n errorMessage : %@", errorDic[@"errorCode"],errorDic[@"errorMessage"]]];
[SVProgressHUD dismiss];
}];
}
}
- (void)messageLoginBtnAction
{
RegisterViewController *regVC = [[RegisterViewController alloc] init];
regVC.type = @"quicklyLogin";
[self.navigationController pushViewController:regVC animated:YES];
}
- (void)registBtnAction
{
RegisterViewController *regVC = [[RegisterViewController alloc] init];
regVC.type = @"register";
[self.navigationController pushViewController:regVC animated:YES];
}
- (void)weChatBtnAction
{
[[CNLiveThirdLoginManager manager] weChatLoginIsBindingThirdParty:NO];
}
- (void)sinaBtnAction
{
[[CNLiveThirdLoginManager manager] sinaLoginIsBindingThirdParty:NO];
}
- (void)qqBtnAction
{
[[CNLiveThirdLoginManager manager] qqLoginIsBindingThirdParty:NO];
}
- (void)checkThirdBtnAction:(UIButton *)button
{
button.selected = !button.selected;
BOOL isCheck = NO;
if (button.selected) {
isCheck = YES;
}else{
isCheck = NO;
}
[CNLiveThirdLoginManager manager].thirdType = ThirdLoginTypeCheckIsRegister;
}
- (void)bindMobileBtnAction:(UIButton *)button
{
button.selected = !button.selected;
BOOL isCheck = NO;
if (button.selected) {
isCheck = YES;
}else{
isCheck = NO;
}
[CNLiveThirdLoginManager manager].thirdType = ThirdLoginTypeBindMobile;
[CNLiveThirdLoginManager manager].bindMobile = _idAndPwdView.idTF.text;
}
- (void)loginSuccess:(NSNotification *)noti
{
if (noti.userInfo)
{//强制绑定手机号
self.dic = noti.userInfo;
}else
{//普通三方登录和验证三方登录
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)loginFailure
{
[SVProgressHUD showErrorWithStatus:@"登录失败"];
}
#pragma mark - touchesBegan
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if ([self.idAndPwdView.idTF isFirstResponder]) {
[self.idAndPwdView.idTF resignFirstResponder];
}
if ([self.idAndPwdView.pwdTF isFirstResponder]) {
[self.idAndPwdView.pwdTF resignFirstResponder];
}
if ([self.verificationCodeTF isFirstResponder]) {
[self.verificationCodeTF resignFirstResponder];
}
}
#pragma mark - getter
- (IdAndPwdView *)idAndPwdView
{
if (!_idAndPwdView) {
_idAndPwdView = [[IdAndPwdView alloc] initWithFrame:CGRectMake(0, 70, KScreenWidth, 114)];
_idAndPwdView.idTF.delegate = self;
_idAndPwdView.pwdTF.delegate = self;
}
return _idAndPwdView;
}
- (UIButton *)loginBtn
{
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_loginBtn setFrame:CGRectMake(10, 250, KScreenWidth - 20, 40)];
[_loginBtn setTitle:@"登 录" forState:UIControlStateNormal];
[_loginBtn addTarget:self action:@selector(loginBtnAction) forControlEvents:UIControlEventTouchUpInside];
_loginBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_loginBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_loginBtn.layer.cornerRadius = 20;
_loginBtn.layer.masksToBounds = YES;
_loginBtn.layer.borderColor = [UIColor blackColor].CGColor;
_loginBtn.layer.borderWidth = 1;
}
return _loginBtn;
}
- (UIButton *)messageLoginBtn
{
if (!_messageLoginBtn) {
_messageLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_messageLoginBtn setFrame:CGRectMake(KScreenWidth - 100, 210, 90, 15)];
[_messageLoginBtn setTitle:@"快捷登录" forState:UIControlStateNormal];
_messageLoginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[_messageLoginBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_messageLoginBtn addTarget:self action:@selector(messageLoginBtnAction) forControlEvents:UIControlEventTouchUpInside];
[_messageLoginBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
}
return _messageLoginBtn;
}
- (UIButton *)registBtn
{
if (!_registBtn) {
_registBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_registBtn setFrame:CGRectMake(0, 0, 40, 15)];
[_registBtn setTitle:@"注册" forState:UIControlStateNormal];
_registBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[_registBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_registBtn addTarget:self action:@selector(registBtnAction) forControlEvents:UIControlEventTouchUpInside];
[_registBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
}
return _registBtn;
}
- (UILabel *)thirdpartyLoginLbl
{
if (!_thirdpartyLoginLbl) {
_thirdpartyLoginLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, KScreenHeight - 200, KScreenWidth, 15)];
_thirdpartyLoginLbl.textAlignment = NSTextAlignmentCenter;
_thirdpartyLoginLbl.textColor = [UIColor blackColor];
_thirdpartyLoginLbl.text = @"第三方账号登录";
_thirdpartyLoginLbl.font = [UIFont systemFontOfSize:15];
}
return _thirdpartyLoginLbl;
}
- (UIButton *)weChatBtn
{
if (!_weChatBtn) {
_weChatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_weChatBtn setFrame:CGRectMake(SpaceWidth, KScreenHeight-150, 80, 40)];
[_weChatBtn setTitle:@"微信" forState:UIControlStateNormal];
[_weChatBtn addTarget:self action:@selector(weChatBtnAction) forControlEvents:UIControlEventTouchUpInside];
_weChatBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_weChatBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_weChatBtn.layer.cornerRadius = 20;
_weChatBtn.layer.masksToBounds = YES;
_weChatBtn.layer.borderColor = [UIColor blackColor].CGColor;
_weChatBtn.layer.borderWidth = 1;
}
return _weChatBtn;
}
- (UIButton *)sinaBtn
{
if (!_sinaBtn) {
_sinaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_sinaBtn setFrame:CGRectMake(SpaceWidth*2+80, KScreenHeight-150, 80, 40)];
[_sinaBtn setTitle:@"微博" forState:UIControlStateNormal];
[_sinaBtn addTarget:self action:@selector(sinaBtnAction) forControlEvents:UIControlEventTouchUpInside];
_sinaBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_sinaBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_sinaBtn.layer.cornerRadius = 20;
_sinaBtn.layer.masksToBounds = YES;
_sinaBtn.layer.borderColor = [UIColor blackColor].CGColor;
_sinaBtn.layer.borderWidth = 1;
}
return _sinaBtn;
}
- (UIButton *)qqBtn
{
if (!_qqBtn) {
_qqBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_qqBtn setFrame:CGRectMake(SpaceWidth*3+80*2, KScreenHeight-150, 80, 40)];
[_qqBtn setTitle:@"QQ" forState:UIControlStateNormal];
[_qqBtn addTarget:self action:@selector(qqBtnAction) forControlEvents:UIControlEventTouchUpInside];
_qqBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_qqBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_qqBtn.layer.cornerRadius = 20;
_qqBtn.layer.masksToBounds = YES;
_qqBtn.layer.borderColor = [UIColor blackColor].CGColor;
_qqBtn.layer.borderWidth = 1;
}
return _qqBtn;
}
- (UIButton *)checkThirdBtn
{
if (!_checkThirdBtn) {
_checkThirdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_checkThirdBtn setFrame:CGRectMake(SpaceWidth, KScreenHeight-100, 150, 40)];
[_checkThirdBtn setTitle:@"三方登录" forState:UIControlStateNormal];
[_checkThirdBtn setTitle:@"三方验证并登录" forState:UIControlStateSelected];
[_checkThirdBtn addTarget:self action:@selector(checkThirdBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_checkThirdBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_checkThirdBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_checkThirdBtn.layer.cornerRadius = 20;
_checkThirdBtn.layer.masksToBounds = YES;
_checkThirdBtn.layer.borderColor = [UIColor blackColor].CGColor;
_checkThirdBtn.layer.borderWidth = 1;
}
return _checkThirdBtn;
}
- (UIButton *)bindMobileBtn
{
if (!_bindMobileBtn) {
_bindMobileBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_bindMobileBtn setFrame:CGRectMake(SpaceWidth, KScreenHeight-50, 180, 40)];
[_bindMobileBtn setTitle:@"三方登录" forState:UIControlStateNormal];
[_bindMobileBtn setTitle:@"三方绑定手机号登录" forState:UIControlStateSelected];
[_bindMobileBtn addTarget:self action:@selector(bindMobileBtnAction:) forControlEvents:UIControlEventTouchUpInside];
_bindMobileBtn.titleLabel.font = [UIFont systemFontOfSize:18];
[_bindMobileBtn setTitleColor:[UIColor colorWithRed:23/255.0 green:110/255.0 blue:254/255.0 alpha:1] forState:UIControlStateNormal];
_bindMobileBtn.layer.cornerRadius = 20;
_bindMobileBtn.layer.masksToBounds = YES;
_bindMobileBtn.layer.borderColor = [UIColor blackColor].CGColor;
_bindMobileBtn.layer.borderWidth = 1;
}
return _bindMobileBtn;
}
- (UITextField *)verificationCodeTF
{
if (!_verificationCodeTF) {
_verificationCodeTF = [[UITextField alloc] initWithFrame:CGRectMake(SpaceWidth + 200, KScreenHeight-50, self.view.bounds.size.width - SpaceWidth - 200, 40)];
_verificationCodeTF.font = [UIFont systemFontOfSize:17];
_verificationCodeTF.keyboardType = UIKeyboardTypeNumberPad;
_verificationCodeTF.placeholder = @"请输入验证码";
_verificationCodeTF.returnKeyType = UIReturnKeyDone;
}
return _verificationCodeTF;
}
- (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