// // AS_LoginC.m // Asteria // // Created by 王猛 on 2023/5/15. // #import "AS_LoginC.h" #import "EamilTFmatchV.h" #import "PassWordSecureBtnV.h" #import "LoginThirdAuthV.h" #import #import "AS_SignUpC.h" #import "LoginForgotC.h" #import "ASLoginBindingC.h" @interface AS_LoginC () @property (nonatomic, strong) UIScrollView *scrollview; @property (nonatomic, strong) EamilTFmatchV *xxx_emailTFV; @property (nonatomic, strong) PassWordSecureBtnV *xxx_passwordV; @property (nonatomic, strong) UIButton *xxx_logInBtn; @property (nonatomic, strong) LoginThirdAuthV *xxx_authV; @property (nonatomic, strong) NSMutableDictionary *thirdLoginParam; @end @implementation AS_LoginC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.customNavBar.hidden = YES; self.navigationController.navigationBar.hidden = YES; self.thirdLoginParam = [[NSMutableDictionary alloc] initWithCapacity:1]; } - (void)initSubviews{ [super initSubviews]; [self.view addSubview:self.scrollview]; UIView *logNav = [self logNavView]; [self.scrollview addSubview:logNav]; UIImageView *Hi_imgV = [[UIImageView alloc]init]; UIImage *hiImg = [UIImage imageNamed:@"login_HI"]; Hi_imgV.image = hiImg; Hi_imgV.frame = CGRectMake(20, CGRectGetMaxY(logNav.frame)+30, KScreenWidth-40, hiImg.size.height/hiImg.size.width*(KScreenWidth-40)); [self.scrollview addSubview:Hi_imgV]; [self.scrollview addSubview:self.xxx_emailTFV]; [self.scrollview addSubview:self.xxx_passwordV]; [self.scrollview bringSubviewToFront:self.xxx_emailTFV]; [self.scrollview addSubview:self.xxx_logInBtn]; [self.scrollview addSubview:self.xxx_authV]; UIView *bottomV = [self load_bottom_v]; [self.scrollview addSubview:bottomV]; self.xxx_emailTFV.mj_y = CGRectGetMaxY(Hi_imgV.frame) + 35; self.xxx_passwordV.frame = CGRectFlatMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20); self.xxx_logInBtn.frame = CGRectMake(20, CGRectGetMaxY(self.xxx_passwordV.frame)+10, KScreenWidth-40, 45); self.xxx_authV.mj_y = CGRectGetMaxY(self.xxx_logInBtn.frame)+30; bottomV.mj_y = CGRectGetMaxY(self.xxx_authV.frame)+30; self.scrollview.contentSize = CGSizeMake(KScreenWidth, CGRectGetMaxY(self.xxx_authV.frame) + 30 + 46 + 34); } -(void)handle_closeEvent:(UIButton *)btn{ [self.navigationController dismissViewControllerAnimated:YES completion:nil]; } -(void)handle_xxx_logInBtnEvent:(UIButton *)btn{//进行登录操 ///登录的跳转 if (self.xxx_emailTFV.xxx_emailTF.text.length == 0 || ![Current_normalTool xxx_isValidateEmail:self.xxx_emailTFV.xxx_emailTF.text]) { [self.view makeToast:@"* Please prvide an email address." duration:2 position:CSToastPositionCenter]; return; }else if(self.xxx_passwordV.xxx_passwordTF.text.length == 0){ [self.view makeToast:@"Please input a password" duration:2 position:CSToastPositionCenter]; return; } NSString *urlStr = [NSString stringWithFormat:@"%@V1/integration/customer/token",AS_Server]; NSMutableDictionary *params = [[NSMutableDictionary alloc]init]; params[@"username"] = self.xxx_emailTFV.xxx_emailTF.text; params[@"password"] = self.xxx_passwordV.xxx_passwordTF.text; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [ASNetTools xxx_loginWithParam:params success:^(id _Nonnull result) { [MBProgressHUD hideHUDForView :self.view animated:YES]; @weakify(self) [self.view makeToast:@"Login Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) { @strongify(self) [self handle_closeEvent:nil]; }]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [MBProgressHUD hideHUDForView :self.view animated:YES]; [self.view makeToast:msg duration:2 position:CSToastPositionCenter]; }]; /* [PPNetworkHelper POST:urlStr parameters:params success:^(id responseObject) { [MBProgressHUD hideHUDForView :self.view animated:YES]; NSDictionary *tmpDic= responseObject; if([tmpDic[@"status"] intValue] ==1){ NSString *token = MM_str(tmpDic[@"data"]); //保存 token [DataUtil setLoginToken:token]; @weakify(self) [self.view makeToast:@"Login Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) { @strongify(self) [self handle_closeEvent:nil]; }]; }else{ [self.view makeToast:MM_str(tmpDic[@"msg"]) duration:2 position:CSToastPositionCenter]; } } failure:^(NSError *error) { [MBProgressHUD hideHUDForView :self.view animated:YES]; if(error == nil){ [self.view makeToast:@"Network request failed" duration:2 position:CSToastPositionCenter]; }else{ NSData *strData = [error userInfo][@"com.alamofire.serialization.response.error.data"]; NSMutableDictionary *temDic =[NSMutableDictionary dictionaryWithDictionary:[PPNetworkHelper too_DataToDic:strData]]; temDic = [UC_CommonmoduleNetWorkTool tt_changeType:temDic]; NSString *errorMsg = @"Network request failed"; if(![Current_normalTool isBlankString:temDic[@"msg"]]){ errorMsg = MM_str(temDic[@"msg"]); } [self.view makeToast:errorMsg duration:2 position:CSToastPositionCenter]; } }]; */ } //注册页面 -(void)handle_signUpEvent:(UIButton *)btn{ AS_SignUpC *upVC = [[AS_SignUpC alloc]init]; [self.navigationController pushViewController:upVC animated:YES]; } -(void)handle_forgetBtnEvent:(UIButton *)btn{ LoginForgotC *forgoC = [[LoginForgotC alloc]init]; [self.navigationController pushViewController:forgoC animated:YES]; } #pragma mark ---- TT_basevDelegate 三方登录授权成功回调 ----- - (void)tengteng_configtaptype:(NSInteger)num data:(id)data { [self.thirdLoginParam removeAllObjects]; [self.thirdLoginParam addEntriesFromDictionary:(NSDictionary *)data]; NSString *userInfoStr = [self.thirdLoginParam objectForKey:@"userInfo"]; NSDictionary *userInfo = [userInfoStr mj_JSONObject]; NSString *emailStr = userInfo[@"email"]; if ([emailStr validateEmail]) { [self requestThirdLogin]; } else {//是否绑定过邮箱 [self requestIsBindEmail:userInfo]; } } //获取用户是否绑定过邮箱 - (void)requestIsBindEmail:(NSDictionary *)info{ [MBProgressHUD showHUDAddedTo:self.view animated:YES]; K_WEAK_SELF; [ASNetTools.shared postWithPath:userVerifyBindEmailUrl param:@{@"identifier":info[@"identifier"], @"type":self.thirdLoginParam[@"hauth_done"]} success:^(id _Nonnull json) { K_STRONG_SELF; [MBProgressHUD hideHUDForView:self.view animated:YES]; ASLoginBindingC *bindVC = [[ASLoginBindingC alloc] init]; bindVC.modalPresentationStyle = UIModalPresentationFullScreen; K_WEAK_SELF; bindVC.bindFinishBlock = ^(NSDictionary * _Nonnull bindInfo) { K_STRONG_SELF; NSString *userInfoStr = [bindInfo mj_JSONString]; [self.thirdLoginParam setObject:userInfoStr forKey:@"userInfo"]; [self requestThirdLogin]; }; [self presentViewController:bindVC animated:YES completion:nil]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { K_STRONG_SELF; [MBProgressHUD hideHUDForView:self.view animated:YES]; [self.view makeToast:msg duration:2 position:CSToastPositionCenter]; }]; } //三方登录接口调用 - (void)requestThirdLogin { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; K_WEAK_SELF; [ASNetTools.shared formData_postWithPath:userThirdLoginUrl param:self.thirdLoginParam success:^(id _Nonnull json) { K_STRONG_SELF; [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *token = [NSString stringWithFormat:@"Bearer %@", json]; [DataUtil setLoginToken:token]; [ASNetTools.shared updateEngine]; [ASUserInfoManager.shared getInfo]; K_WEAK_SELF; [self.view makeToast:@"Login Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) { K_STRONG_SELF; [self handle_closeEvent:nil]; }]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { K_STRONG_SELF; [MBProgressHUD hideHUDForView:self.view animated:YES]; [self.view makeToast:msg duration:2 position:CSToastPositionCenter]; }]; } #pragma mark - **************** 懒加载 **************** -(UIView *)logNavView{ IPhoneXHeigh UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, securitytop_Y)]; UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [closeBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateNormal]; [closeBtn addTarget:self action:@selector(handle_closeEvent:) forControlEvents:UIControlEventTouchUpInside]; closeBtn.frame = CGRectMake(20, securitytop_Y-44, 44, 44); [topView addSubview:closeBtn]; UIImageView *headImg = [[UIImageView alloc]init]; UIImage *bannerImg = [UIImage imageNamed:@"common_headLogo"]; headImg.image = bannerImg ; headImg.frame = CGRectMake((KScreenWidth- bannerImg.size.width)/2, (IPHONEX ? 44 : 20)+20 , bannerImg.size.width, bannerImg.size.height); [topView addSubview:headImg]; closeBtn.centerY = topView.centerY; headImg.centerY = topView.centerY; return topView; } - (UIScrollView *)scrollview { if (!_scrollview) { _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)]; } return _scrollview; } -(EamilTFmatchV *)xxx_emailTFV{ if (!_xxx_emailTFV) { _xxx_emailTFV = [[EamilTFmatchV alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)]; // _xxx_emailTFV.xxx_emailTF.text = @"845600348@qq.com"; } return _xxx_emailTFV; } - (PassWordSecureBtnV *)xxx_passwordV { if (!_xxx_passwordV) { _xxx_passwordV = [[PassWordSecureBtnV alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20)]; // _xxx_passwordV.xxx_passwordTF.text = @"nuli322103"; } return _xxx_passwordV; } - (UIButton *)xxx_logInBtn { if (!_xxx_logInBtn) { _xxx_logInBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_xxx_logInBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal]; _xxx_logInBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16]; [_xxx_logInBtn setTitle:@"LOG IN" forState:UIControlStateNormal]; [_xxx_logInBtn addTarget:self action:@selector(handle_xxx_logInBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; _xxx_logInBtn.backgroundColor = ThemeColor; _xxx_logInBtn.layer.cornerRadius = 4; _xxx_logInBtn.clipsToBounds = YES; } return _xxx_logInBtn; } - (LoginThirdAuthV *)xxx_authV { if (!_xxx_authV) { _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)]; _xxx_authV.basedelegate = self; } return _xxx_authV; } -(UIView *)load_bottom_v{ UIView *bottomV = [[UIView alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-40, 46)]; QMUILabel *disLab = [[QMUILabel alloc]init]; disLab.text = @"Don't Have An Account?"; disLab.font = [UIFont fontWithName:Rob_Regular size:12]; [bottomV addSubview:disLab]; UIButton *signUpBtn = [UIButton buttonWithType:UIButtonTypeCustom]; signUpBtn.backgroundColor = [UIColor clearColor]; NSMutableAttributedString *sinAtr = [[NSMutableAttributedString alloc]initWithString:@"Sign Up" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}]; [signUpBtn setAttributedTitle:sinAtr forState:UIControlStateNormal]; [signUpBtn addTarget:self action:@selector(handle_signUpEvent:) forControlEvents:UIControlEventTouchUpInside]; [signUpBtn setTitleColor:ThemeColor forState:UIControlStateNormal]; signUpBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12]; [bottomV addSubview:signUpBtn]; UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom]; forgetBtn.backgroundColor = [UIColor clearColor]; NSMutableAttributedString *forgotAtr = [[NSMutableAttributedString alloc]initWithString:@"Forgot Your Password" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}]; [forgetBtn setAttributedTitle:forgotAtr forState:UIControlStateNormal]; [forgetBtn setTitleColor:ThemeColor forState:UIControlStateNormal]; forgetBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12]; [forgetBtn addTarget:self action:@selector(handle_forgetBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; [bottomV addSubview:forgetBtn]; [disLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.mas_equalTo(0); make.height.mas_equalTo(16); }]; [signUpBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(disLab); make.left.equalTo(disLab.mas_right).offset(3); make.height.mas_equalTo(20); make.width.mas_equalTo(45); }]; [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.equalTo(disLab.mas_bottom).offset(10); make.height.mas_equalTo(20); make.width.mas_equalTo(120); }]; return bottomV; } @end