重庆迈尖科技有限公司
2019-05-08 8c116459f2308e9f8564ea8f55b2ca25849b8336
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
//
//  LoggingViewController.m
//  mgysVideo
//
//  Created by weikou on 16/7/19.
//  Copyright © 2016年 wgj. All rights reserved.
//
 
/************************
 *Tip
 *这个登录视图会在详细页面的评论模块使用模态跳转,所以这个视图会用两种方式推出视图
 *************************/
 
#import <AVFoundation/AVFoundation.h>
#import "LoggingViewController.h"
#import "RegisteViewController.h"
#import "forgetPasswordViewController.h"
#import "SettingWebView.h"
 
@interface LoggingViewController (){
    UITextField *accountNumber;
    UITextField *PasswordNumber;
    UIButton *LoginBtn;
}
 
@end
 
@implementation LoggingViewController{
    
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=KGlobalLightGreyColor_245;
    //初始化登录界面
    [self initScene];
}
 
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"登录界面"];
}
 
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"登录界面"];
}
 
/**
 *  界面初始化
 */
-(void)initScene{
    self.navigationItem.title = @"账号登录";
    self.view.backgroundColor=[UIColor whiteColor];
    //设置账号登录的字体样式
    self.navigationController.navigationBar.titleTextAttributes =@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]};
    //设置返回按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 32, 32);
    UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = iconBarItem;
    
    //设置使用模态跳转的返回按钮
    if(_ispresent){
        //隐藏状态栏
        [[UIApplication sharedApplication] setStatusBarHidden:YES];
        //添加返回按钮
        CGFloat height = 15;
        if (KIsiPhoneX) {
            height = 35;
        }
        UIButton *backButton=[[UIButton alloc] initWithFrame:CGRectMake(15, height, 32, 32)];
        [backButton setImage:[UIImage imageNamed:@"取消登录"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(presentBack) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:backButton];
    }
    
    //账号
    UILabel *account=[[UILabel alloc] init];
    //账号输入框
    accountNumber=[[UITextField alloc] init];
    //分割线
    UILabel *Dividing_line=[[UILabel alloc] init];
    //密码
    UILabel *password=[[UILabel alloc] init];
    //密码输入框
    PasswordNumber=[[UITextField alloc] init];
    //分割线
    UILabel *Dividing_line2=[[UILabel alloc] init];
    //是否同意协议
    UIButton *agreeBtn=[[UIButton alloc] init];
    //协议
    UIButton *agreeItem=[[UIButton alloc] init];
    //忘记密码
    UIButton *forgetedPassword=[[UIButton alloc] init];
    //注册
    UIButton *registerBtn=[[UIButton alloc] init];
    //登录
    LoginBtn=[[UIButton alloc] init];
    if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
        //表头图片
        UIImageView *titleImage=[[UIImageView alloc] initWithFrame:CGRectMake(60, 85, KScreenW-120,(KScreenW-120)/394*171)];
        titleImage.image=[UIImage imageNamed:@"登录表头"];
        [self.view addSubview:titleImage];
        
        //账号
        account.frame=CGRectMake(50, 100+(KScreenW-120)/394*171, 44,30);
        //账号输入框
        accountNumber.frame=CGRectMake(95, 100+(KScreenW-120)/394*171, KScreenW-145, 30);
        //分割线
        Dividing_line.frame=CGRectMake(50, 135+(KScreenW-120)/394*171, KScreenW-110, 0.5);
        //密码
        password.frame=CGRectMake(50, 140+(KScreenW-120)/394*171, 44, 30);
        //密码输入框
        PasswordNumber.frame=CGRectMake(95, 140+(KScreenW-120)/394*171, KScreenW-145, 30);
        //分割线
        Dividing_line2.frame=CGRectMake(50, 175+(KScreenW-120)/394*171, KScreenW-110, 0.5);
        //是否同意协议
        if ([UIScreen mainScreen].bounds.size.width>=375.0) {
            agreeBtn.frame=CGRectMake(60, 195+(KScreenW-120)/394*171, 14, 14);
        }else{
            agreeBtn.frame=CGRectMake(KScreenW/2-80-15, 220+(KScreenW-120)/394*171, 14, 14);
        }
        //协议
        if ([UIScreen mainScreen].bounds.size.width>=375.0) {
            agreeItem.frame=CGRectMake(75, 192+(KScreenW-120)/394*171, 160, 20);
        }else{
            agreeItem.frame=CGRectMake(KScreenW/2-80, 217+(KScreenW-120)/394*171, 160, 20);
        }
        //忘记密码
        if ([UIScreen mainScreen].bounds.size.width>=375.0) {
            forgetedPassword.frame=CGRectMake(240, 192+(KScreenW-120)/394*171, 100, 20);
        }else{
            forgetedPassword.frame=CGRectMake(KScreenW-150, 192+(KScreenW-120)/394*171, 100, 20);
        }
        //注册
        registerBtn.frame=CGRectMake(60, 250+(KScreenW-120)/394*171, (KScreenW-150)/2-20, 35);
        //登录
        LoginBtn.frame=CGRectMake(60+(KScreenW-150)/2, 250+(KScreenW-120)/394*171, (KScreenW-150)/2+40, 35);
    }else{
        //账号
        account.frame=CGRectMake(50, 100, 44,30);
        //账号输入框
        accountNumber.frame=CGRectMake(95, 100, KScreenW-145, 30);
        //分割线
        Dividing_line.frame=CGRectMake(50, 135, KScreenW-110, 0.5);
        //密码
        password.frame=CGRectMake(50, 140, 44, 30);
        //密码输入框
        PasswordNumber.frame=CGRectMake(95, 140, KScreenW-145, 30);
        //分割线
        Dividing_line2.frame=CGRectMake(50, 175, KScreenW-110, 0.5);
        //是否同意协议
        agreeBtn.frame=CGRectMake(KScreenW/2-80-15, 220, 14, 14);
        //协议
        agreeItem.frame=CGRectMake(KScreenW/2-80, 217, 160, 20);
        //忘记密码
        forgetedPassword.frame=CGRectMake(KScreenW-150, 192, 100, 20);
        //注册
        registerBtn.frame=CGRectMake(60, 250, (KScreenW-150)/2-20, 35);
        //登录
        LoginBtn.frame=CGRectMake(60+(KScreenW-150)/2, 250, (KScreenW-150)/2+40, 35);
    }
    
    //账号
    account.text=@"账号:";
    account.textColor=kGlobalMainColor;
    [self.view addSubview:account];
    
    //账号输入框
    accountNumber.keyboardType=UIKeyboardTypeEmailAddress;
    accountNumber.autocorrectionType=UITextAutocorrectionTypeNo;
    [self.view addSubview:accountNumber];
    
    //分割线
    Dividing_line.backgroundColor=kGlobalLightGreyColor_223;
    [self.view addSubview:Dividing_line];
    
    //密码
    password.text=@"密码:";
    password.textColor=kGlobalMainColor;
    [self.view addSubview:password];
    
    //密码输入框
    PasswordNumber.secureTextEntry=YES;
    [self.view addSubview:PasswordNumber];
    
    //分割线
    Dividing_line2.backgroundColor=kGlobalLightGreyColor_223;
    [self.view addSubview:Dividing_line2];
    
    //是否同意协议
    [agreeBtn setImage:[UIImage imageNamed:@"同意协议"] forState:UIControlStateNormal];
    [agreeBtn setImage:[UIImage imageNamed:@"同意协议1"] forState:UIControlStateSelected];
    [agreeBtn addTarget:self action:@selector(changeAgreeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [agreeBtn setSelected:YES];
    [self.view addSubview:agreeBtn];
    
    //协议
    NSString *contentStr=[NSString stringWithFormat:@"用户使用协议&隐私条款"];
    NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
    [attriStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:1] range:NSMakeRange(0, contentStr.length)];
    [attriStr addAttribute:NSUnderlineColorAttributeName value:kGlobalLightBlueColor range:NSMakeRange(0, contentStr.length)];
    [attriStr addAttribute:NSForegroundColorAttributeName value:kGlobalLightBlueColor range:NSMakeRange(0, contentStr.length)];
    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, contentStr.length)];
    
    [agreeItem setAttributedTitle:attriStr forState:UIControlStateNormal];
    [agreeItem addTarget:self action:@selector(LookItem) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:agreeItem];
    
    //忘记密码
    NSString *contentStr2=[NSString stringWithFormat:@"忘记密码?"];
    NSMutableAttributedString * attriStr2 = [[NSMutableAttributedString alloc] initWithString:contentStr2];
    [attriStr2 addAttribute:NSForegroundColorAttributeName value:kGlobalMainColor range:NSMakeRange(0, contentStr2.length)];
    [attriStr2 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, contentStr2.length)];
    
    [forgetedPassword setAttributedTitle:attriStr2 forState:UIControlStateNormal];
    [forgetedPassword addTarget:self action:@selector(forgetThePassWord) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgetedPassword];
    
    //注册
    [registerBtn.layer setMasksToBounds:YES];
    [registerBtn.layer setCornerRadius:8.0];
    [registerBtn.layer setBorderWidth:1.0];
    [registerBtn.layer setBorderColor:(kGlobalMainColor.CGColor)];
    [registerBtn setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
    [registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    [registerBtn addTarget:self action:@selector(registeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerBtn];
    
    //登录
    [LoginBtn.layer setMasksToBounds:YES];
    [LoginBtn.layer setCornerRadius:8.0];
    [LoginBtn setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
    [LoginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [LoginBtn setBackgroundColor:kGlobalYellowColor];
    [LoginBtn addTarget:self action:@selector(LoginClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:LoginBtn];
    
    //第三方登录
    UIView * thirdView=[[UIView alloc] initWithFrame:CGRectMake(0, KScreenH-170, KScreenW, 170)];
    thirdView.backgroundColor=KGlobalLightGreyColor_255;
    [self.view addSubview:thirdView];
    
    //第三方登录的标头
    UIImageView *thirdtitle=[[UIImageView alloc] initWithFrame:CGRectMake((KScreenW-210)/2, 20, 210, 23)];
    thirdtitle.image=[UIImage imageNamed:@"三方登录标头"];
    [thirdView addSubview:thirdtitle];
    
    //QQ登录
    UIButton * QQLoginButton=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW/2-30, thirdView.frame.size.height/2-30, 60, 60)];
    [QQLoginButton setBackgroundImage:[UIImage imageNamed:@"QQLogin"] forState:UIControlStateNormal];
    [QQLoginButton addTarget:self action:@selector(ClickQQ:) forControlEvents:UIControlEventTouchUpInside];
    [thirdView addSubview:QQLoginButton];
    
    UILabel * QQLabel=[[UILabel alloc] initWithFrame:CGRectMake(KScreenW/2-30, thirdView.frame.size.height/2+30, 60, 40)];
    QQLabel.textAlignment = NSTextAlignmentCenter;
    QQLabel.text=@"QQ";
    QQLabel.font=[UIFont systemFontOfSize:17];
    [thirdView addSubview:QQLabel];
    
    if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
        thirdView.hidden = YES;
    }else{
        thirdView.hidden = NO;
 
    }
    
}
 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [PasswordNumber resignFirstResponder];
    [accountNumber resignFirstResponder];
}
 
/**
 用户同意或取消用户使用协议&隐私条款
 
 @param sender 传入按钮
 */
-(void)changeAgreeBtn:(UIButton *)sender{
    if([sender isSelected]){
        [sender setSelected:NO];
        [LoginBtn setEnabled:NO];
        LoginBtn.backgroundColor=[UIColor lightGrayColor];
    }else{
        [sender setSelected:YES];
        [LoginBtn setEnabled:YES];
        LoginBtn.backgroundColor=kGlobalYellowColor;
    }
}
 
/**
 用户查看用户使用协议&隐私条款
 */
-(void)LookItem{
    SettingWebView *settingwebVC=[[SettingWebView alloc] init];
    settingwebVC.webTitle=@"用户协议&隐私条款";
    settingwebVC.requestURL=[NSString stringWithFormat:@"%@/api_control_ios.jsp",iconImageUrl];
    if(_ispresent){//模态跳转
        settingwebVC.ispresent = YES;
        [self presentViewController:settingwebVC animated:YES completion:^{
            
        }];
    }else{
        [self.navigationController pushViewController:settingwebVC animated:YES];
    }
}
 
/**
 忘记密码
 */
-(void)forgetThePassWord{
    forgetPasswordViewController *forgetPasswordVC=[[forgetPasswordViewController alloc] init];
    forgetPasswordVC.ispresent=_ispresent;
    forgetPasswordVC.accountNum=accountNumber.text;
    if(_ispresent){//模态跳转
        [self presentViewController:forgetPasswordVC animated:YES completion:^{
            
        }];
    }else{
        [self.navigationController pushViewController:forgetPasswordVC animated:YES];
    }
}
 
/**
 注册响应事件
 */
-(void)registeClick{
    RegisteViewController *RegisteVC=[[RegisteViewController alloc] init];
    RegisteVC.ispresent=_ispresent;
    if(_ispresent){//模态跳转
        [self presentViewController:RegisteVC animated:YES completion:^{
            
        }];
    }else{
        [self.navigationController pushViewController:RegisteVC animated:YES];
    }
}
 
/**
 响应账号登录事件
 */
-(void)LoginClick{
    if(accountNumber.text.length == 0){
        [Share ShakeView:accountNumber WithInfomation:@"请输入正确的邮箱地址!"];
        return;
    }
  
    if (![Share isEmailAddress:accountNumber.text]) {
        //账号格式不正确
        [Share ShakeView:accountNumber WithInfomation:@"请输入正确的邮箱地址!"];
    }else if(PasswordNumber.text.length == 0){
        [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"账号或密码错误"]];
        return;
    }else{
        
        [SVProgressHUD showWithStatus:@"登陆中"];
        [[YTHNetInterface startInterface] getloginWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithEmail:accountNumber.text WithPwd:PasswordNumber.text withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                NSString *err=[NSString stringWithFormat:@"%@",[result objectForKey:@"Error"]];
                if (err.length==0) {
                    [SVProgressHUD dismiss];
                    //LoginUid
                    [[NSUserDefaults standardUserDefaults] setObject:[[result objectForKey:@"Data"] objectForKey:@"Id"] forKey:@"LoginUid"];
                    [[NSUserDefaults standardUserDefaults] setObject:[[result objectForKey:@"Data"] objectForKey:@"Nickname"] forKey:@"QQUserName"];
                    [[NSUserDefaults standardUserDefaults] setObject:[[result objectForKey:@"Data"] objectForKey:@"Portrait"] forKey:@"iconURL"];
                    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"userOnLine"];
                    //通知视图刷新
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOAD_DATA" object:nil];
                    if (_ispresent) {
                        [self presentBack];
                    }else{
                        [self back];
                    }
                }else{
                    //登录失败
                    [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"账号或密码错误"]];
                    PasswordNumber.text=@"";
                }
                
            }else{
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"账号或密码错误"]];
                PasswordNumber.text=@"";
 
                
            }
        }];
    }
}
 
/**
 *  点击QQ登录
 *
 *  @param sender QQ登录的按钮
 */
-(void)ClickQQ:(UIButton*)sender{
    
    if (![[UIApplication sharedApplication] canOpenURL:[NSURL  URLWithString:@"mqq://"]]){
        [SVProgressHUD showInfoWithStatus:@"您还没有安装QQ哦"];
 
        return;
    }
 
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            
        }else{
        //提示用户,正在登陆中
        [SVProgressHUD showWithStatus:@"拼命登陆中..."];
        
        UMSocialUserInfoResponse *snsAccount = result;
        
        [[YTHNetInterface startInterface] getThirdPartyWithWithUid:[YTHsharedManger startManger].Uid withOpenId:snsAccount.openid WithName:snsAccount.name WithPortrait:snsAccount.iconurl WithLoginType:@"1" withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                [SVProgressHUD dismiss];
                //LoginUid的设置在YTHNetInterface中,点击上面的的请求函数,就可以看见!
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"userOnLine"];
                [self getInfoFromInternet];
                if (_ispresent) {
                    [self presentBack];
                }else{
                    [self back];
                }
            }else{
                //通知用户登录失败
                [SVProgressHUD showErrorWithStatus:@"登陆失败!"];
            }
        }];
        }
    }];
}
 
/**
 从网络获取数据
 */
-(void)getInfoFromInternet{
    [[YTHNetInterface startInterface] getLoginUserInfoWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            //首先判断数据是否获成功
            NSString *err=[NSString stringWithFormat:@"%@",[result objectForKey:@"Error"]];
            if (err.length==0) {
                //跟新个人信息到全局变量
                if ([[result objectForKey:@"Data"] objectForKey:@"Portrait"]!=nil) {
                    NSString *str=[[result objectForKey:@"Data"] objectForKey:@"Portrait"];
                    if ([[str substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
                    }else{
                        str=[NSString stringWithFormat:@"%@%@",iconImageUrl,str];
                    }
                    [[NSUserDefaults standardUserDefaults] setObject:str forKey:@"iconURL"];
                }
                if ([[result objectForKey:@"Data"] objectForKey:@"Nickname"]!=nil) {
                    [[NSUserDefaults standardUserDefaults] setObject:[[result objectForKey:@"Data"] objectForKey:@"Nickname"] forKey:@"QQUserName"];
                }
                //通知刷新视图
                [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOAD_DATA" object:nil];
            }
        }
    }
     ];
}
 
 
 
/**
 *  退出
 */
-(void)back{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
 
 
/**
 *  使用模态跳转的退出
 */
-(void)presentBack{
    [self dismissViewControllerAnimated:YES completion:^{
        //状态栏重现
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }];
}
 
@end