//
|
// 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
|