//
|
// LoginPage.m
|
// GoldRich
|
//
|
// Created by WindShan on 2017/2/9.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "LoginPage.h"
|
#import "GloriaLabel.h"
|
#import "RegistPage.h"
|
#import "FogetPwdPage.h"
|
#import "HomePage.h"
|
#import "CommonReqModel.h"
|
#import "NetworkSingleton.h"
|
#import "UserModel.h"
|
|
@interface LoginPage ()
|
{
|
UIButton * nomalLoginBtn;
|
|
UITextField * userPhoneTextField;
|
UITextField * userPwdTextFeild;
|
|
UIButton * registBtn;
|
UIButton * forgetBtn;
|
|
}
|
|
@end
|
|
@implementation LoginPage
|
|
-(void)viewWillAppear:(BOOL)animated
|
{
|
[super viewWillAppear:YES];
|
|
self.navigationController.navigationBarHidden = YES;
|
|
if([UserDefault stringForKey:@"isLogin"] != nil && [[UserDefault stringForKey:@"isLogin"] intValue] == 1 )
|
{
|
// 跳转主界面
|
[GetAppDelegate getUserInfo];
|
}
|
|
}
|
-(void)viewDidDisappear:(BOOL)animated
|
{
|
[super viewDidDisappear:YES];
|
//self.navigationController.navigationBarHidden = NO;
|
}
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
// Do any additional setup after loading the view.
|
|
|
UIImageView * loginBk = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
|
loginBk.image = [UIImage imageNamed:@"login_bk"];
|
[self.view addSubview:loginBk];
|
|
// 初始化 pagecontrol
|
CGFloat logoHeight = 134;
|
CGFloat logoWidth = 113;
|
CGFloat tipsLabelHeight = NavBarHeight7+75+30;
|
CGFloat textFieldW = 292;
|
CGFloat textFieldH = 56;
|
|
if( IsiPhone4 || IsiPhone5)
|
{
|
logoWidth = 80;
|
logoHeight = 90;
|
tipsLabelHeight = NavBarHeight7+70+10;
|
textFieldH = 50;
|
}
|
|
|
UIImageView * logoPic = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-logoWidth)/2, NavBarHeight7, logoWidth, logoHeight)];
|
logoPic.image = [UIImage imageNamed:@"login_logo"];
|
[self.view addSubview:logoPic];
|
|
UIImageView * edit_bkimg = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2-120, textFieldW, textFieldH)];
|
edit_bkimg.image = [UIImage imageNamed:@"edit_bk"];
|
[self.view addSubview:edit_bkimg];
|
|
UIImageView * edit_name_tagimg = [[UIImageView alloc] initWithFrame:CGRectMake(15, (textFieldH-22)/2, 22, 22)];
|
edit_name_tagimg.image = [UIImage imageNamed:@"edit_name_tag"];
|
[edit_bkimg addSubview:edit_name_tagimg];
|
|
userPhoneTextField = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2+40, SCREEN_HEIGHT/2-120, textFieldW-40, textFieldH)];
|
userPhoneTextField.font = [UIFont fontWithName:@"Arial" size:16];
|
userPhoneTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入用户名"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}];
|
userPhoneTextField.delegate = self;
|
[userPhoneTextField setValue:RgbColor(149, 149, 150) forKeyPath:@"_placeholderLabel.textColor"];
|
//userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
|
userPhoneTextField.textColor = RgbColor(149, 149, 150);
|
userPhoneTextField.keyboardType = UIKeyboardTypeNumberPad;
|
userPhoneTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
|
// 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
|
UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(userPhoneTextField.frame.origin.x,userPhoneTextField.frame.origin.y,10.0, userPhoneTextField.frame.size.height)];
|
|
userPhoneTextField.leftView = blankView;
|
userPhoneTextField.leftViewMode =UITextFieldViewModeAlways;
|
[self.view addSubview:userPhoneTextField];
|
|
UIImageView * edit_bkimg2 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2-60, textFieldW, textFieldH)];
|
edit_bkimg2.image = [UIImage imageNamed:@"edit_bk"];
|
[self.view addSubview:edit_bkimg2];
|
|
UIImageView * edit_name_tagimg2 = [[UIImageView alloc] initWithFrame:CGRectMake(15, (textFieldH-22)/2, 22, 22)];
|
edit_name_tagimg2.image = [UIImage imageNamed:@"edit_pwd_tag"];
|
[edit_bkimg2 addSubview:edit_name_tagimg2];
|
|
|
userPwdTextFeild = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2+40, SCREEN_HEIGHT/2-60, textFieldW-40, textFieldH)];
|
userPwdTextFeild.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入密码"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}];
|
userPwdTextFeild.secureTextEntry = YES;
|
userPwdTextFeild.font = [UIFont fontWithName:@"Arial" size:16];
|
userPwdTextFeild.delegate = self;
|
[userPwdTextFeild setValue:RgbColor(149, 149, 150) forKeyPath:@"_placeholderLabel.textColor"];
|
//userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
|
userPwdTextFeild.textColor = RgbColor(149, 149, 150);
|
userPwdTextFeild.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
|
// 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
|
UIView *blankView2 = [[UIView alloc] initWithFrame:CGRectMake(userPwdTextFeild.frame.origin.x,userPwdTextFeild.frame.origin.y,10.0, userPwdTextFeild.frame.size.height)];
|
userPwdTextFeild.leftView = blankView2;
|
userPwdTextFeild.leftViewMode =UITextFieldViewModeAlways;
|
[self.view addSubview:userPwdTextFeild];
|
|
nomalLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
nomalLoginBtn.frame = CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2+60, textFieldW, textFieldH);
|
[nomalLoginBtn setBackgroundImage:[UIImage imageNamed:@"login_btn_bk" ] forState:UIControlStateNormal];
|
[nomalLoginBtn setTitle:@"登 录" forState:UIControlStateNormal];
|
nomalLoginBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
|
[nomalLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
nomalLoginBtn.layer.masksToBounds=YES;
|
nomalLoginBtn.layer.cornerRadius=8.0f;
|
[nomalLoginBtn addTarget:self action:@selector(userLogin) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:nomalLoginBtn];
|
|
forgetBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
forgetBtn.frame = CGRectMake(SCREEN_WIDTH-140, SCREEN_HEIGHT/2+45-30, 120, 40);
|
[forgetBtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
|
forgetBtn.titleLabel.font = [UIFont systemFontOfSize: 16.0];
|
[forgetBtn setTitleColor:kUIColorFromRGB(0x8c928d) forState:UIControlStateNormal];
|
[forgetBtn addTarget:self action:@selector(fogotPwdAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:forgetBtn];
|
|
registBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
registBtn.frame = CGRectMake((SCREEN_WIDTH-120)/2, SCREEN_HEIGHT/2+225, 120, 40);
|
[registBtn setTitle:@"新用户注册" forState:UIControlStateNormal];
|
registBtn.titleLabel.font = [UIFont systemFontOfSize: 16.0];
|
[registBtn setTitleColor:kUIColorFromRGB(0x269af4) forState:UIControlStateNormal];
|
[registBtn addTarget:self action:@selector(registAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:registBtn];
|
|
|
|
|
}
|
|
#pragma mark - begin
|
-(void) userLogin
|
{
|
// 重置密码操作
|
if(userPhoneTextField.text.length == 0)
|
{
|
[Global alertMessageEx:@"请输入手机号." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
else if(userPwdTextFeild.text.length == 0)
|
{
|
[Global alertMessageEx:@"请输入登录密码." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
else
|
{
|
// 执行登录操作
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
HUD.labelText = @"登录中...";
|
// 隐藏时候从父控件中移除
|
HUD.removeFromSuperViewOnHide = YES;
|
// YES代表需要蒙版效果
|
HUD.dimBackground = YES;
|
|
NSString *path = [[NSString alloc] initWithFormat:USER_LOGIN];
|
|
CommonReqModel * model = [[CommonReqModel alloc] init];
|
[model setPhone:userPhoneTextField.text];
|
[model setPassword:userPwdTextFeild.text];
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody)
|
{
|
HUD.hidden = YES;
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
if(resModel.code == 0)
|
{
|
if(![Global isEmptyObject:resModel.content])
|
{
|
// 成功处理
|
_loginUser = [resModel.content mutableCopy];
|
|
UserModel * userModel = [UserModel mj_objectWithKeyValues:resModel.content];
|
|
// 存储用户信息
|
[UserDefault setObject:@"1" forKey:@"isLogin"];
|
[UserDefault setObject:userModel._id forKey:@"user_id"];
|
[UserDefault setObject:userModel.phone forKey:@"phone"];
|
[UserDefault setObject:userModel.password forKey:@"password"];
|
[UserDefault setObject:userModel.nickname forKey:@"nickname"];
|
[UserDefault setObject:userModel.video forKey:@"video"];
|
[UserDefault setObject:userModel.refresh_frequency forKey:@"refresh_frequency"];
|
[UserDefault setObject:userModel.is_open_upload forKey:@"is_open_upload"];
|
[UserDefault synchronize];//使用synchronize强制立即将数据写入磁盘,防止在写完NSUserDefaults后程序退出导致的数据丢失
|
|
// 跳转主界面
|
//[GetAppDelegate showHomePage];
|
// 调转重置界面操作
|
HomePage * page = [[HomePage alloc] init];
|
[weakself.navigationController pushViewController:page animated:YES];
|
}
|
else
|
{
|
// 出错处理
|
[UserDefault setObject:@"0" forKey:@"isLogin"];
|
[Global alertMessageEx:resModel.desc title:@"登录失败" okTtitle:nil cancelTitle:@"确定" delegate:self];
|
}
|
|
}
|
else
|
{
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
failure:^(NSString *error)
|
{
|
HUD.hidden = YES;
|
[Global alertMessageEx:error title:@"登录失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
}
|
|
}
|
|
-(void) fogotPwdAction
|
{
|
// 调转重置界面操作
|
FogetPwdPage * fogetPwdPage = [[FogetPwdPage alloc] initIsFirstPage:NO];
|
[self.navigationController pushViewController:fogetPwdPage animated:YES];
|
}
|
|
-(void) registAction
|
{
|
// 调转注册界面操作
|
RegistPage * registPage = [[RegistPage alloc] initIsFirstPage:NO];
|
[self.navigationController pushViewController:registPage animated:YES];
|
}
|
|
|
#pragma mark - end
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
|
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
{
|
NSInteger textLength = 0;
|
|
if ([string isEqualToString:@""]) {
|
textLength = textField.text.length-1;
|
}
|
else
|
{
|
textLength = textField.text.length+1;
|
}
|
|
BOOL flag = NO;
|
if( textField == userPhoneTextField )
|
{
|
// 检测手机号是否合法
|
if( textLength == 11 && [StringUtil isMobile:[userPhoneTextField.text stringByAppendingString:string]] == NO)
|
{
|
[Global alertMessage:@"手机号码不合法,请重新输入!"];
|
}
|
|
// 大于11位数不让输入
|
if( textLength > 11 )
|
return NO;
|
}
|
|
flag = YES;
|
if (flag)
|
{
|
// [loginBtn setBackgroundColor:BLUECOLOR];
|
// loginBtn.userInteractionEnabled = YES;
|
}
|
else
|
{
|
// loginBtn.backgroundColor = [UIColor lightGrayColor];
|
// loginBtn.userInteractionEnabled = NO;
|
}
|
|
return flag;
|
}
|
|
-(BOOL)textFieldShouldReturn:(UITextField *)textField
|
{
|
if ([textField isFirstResponder]) {
|
[textField resignFirstResponder];
|
}
|
return YES;
|
}
|
|
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
{
|
[self textFieldShouldReturn:userPhoneTextField];
|
[self textFieldShouldReturn:userPwdTextFeild];
|
}
|
|
/*
|
#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
|