LoginViewController.m
8.17 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
//
// 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;
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"登录";
self.view.backgroundColor = [UIColor whiteColor];
[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];
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
{
[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)loginSuccess
{
[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];
}
}
#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.backgroundColor = [UIColor orangeColor];
[_loginBtn setFrame:CGRectMake(10, 250, KScreenWidth - 20, 40)];
_loginBtn.layer.cornerRadius = 20;
_loginBtn.layer.masksToBounds = YES;
[_loginBtn setTitle:@"登 录" forState:UIControlStateNormal];
[_loginBtn addTarget:self action:@selector(loginBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
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];
}
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];
}
return _registBtn;
}
- (UILabel *)thirdpartyLoginLbl
{
if (!_thirdpartyLoginLbl) {
_thirdpartyLoginLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, KScreenHeight - 200, KScreenWidth, 15)];
_thirdpartyLoginLbl.textAlignment = NSTextAlignmentCenter;
_thirdpartyLoginLbl.textColor = [UIColor orangeColor];
_thirdpartyLoginLbl.text = @"第三方账号登录";
_thirdpartyLoginLbl.font = [UIFont systemFontOfSize:15];
}
return _thirdpartyLoginLbl;
}
- (UIButton *)weChatBtn
{
if (!_weChatBtn) {
_weChatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_weChatBtn.backgroundColor = [UIColor orangeColor];
[_weChatBtn setFrame:CGRectMake(SpaceWidth, KScreenHeight-150, 80, 40)];
_weChatBtn.layer.cornerRadius = 20;
_weChatBtn.layer.masksToBounds = YES;
[_weChatBtn setTitle:@"微信" forState:UIControlStateNormal];
[_weChatBtn addTarget:self action:@selector(weChatBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _weChatBtn;
}
- (UIButton *)sinaBtn
{
if (!_sinaBtn) {
_sinaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_sinaBtn.backgroundColor = [UIColor orangeColor];
[_sinaBtn setFrame:CGRectMake(SpaceWidth*2+80, KScreenHeight-150, 80, 40)];
_sinaBtn.layer.cornerRadius = 20;
_sinaBtn.layer.masksToBounds = YES;
[_sinaBtn setTitle:@"微博" forState:UIControlStateNormal];
[_sinaBtn addTarget:self action:@selector(sinaBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _sinaBtn;
}
- (UIButton *)qqBtn
{
if (!_qqBtn) {
_qqBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_qqBtn.backgroundColor = [UIColor orangeColor];
[_qqBtn setFrame:CGRectMake(SpaceWidth*3+80*2, KScreenHeight-150, 80, 40)];
_qqBtn.layer.cornerRadius = 20;
_qqBtn.layer.masksToBounds = YES;
[_qqBtn setTitle:@"QQ" forState:UIControlStateNormal];
[_qqBtn addTarget:self action:@selector(qqBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _qqBtn;
}
- (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