AS_LoginC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. //
  2. // AS_LoginC.m
  3. // Asteria
  4. //
  5. // Created by 王猛 on 2023/5/15.
  6. //
  7. #import "AS_LoginC.h"
  8. #import "EamilTFmatchV.h"
  9. #import "PassWordSecureBtnV.h"
  10. #import "LoginThirdAuthV.h"
  11. #import <AFNetworking/AFNetworking.h>
  12. #import "AS_SignUpC.h"
  13. #import "LoginForgotC.h"
  14. #import "ASLoginBindingC.h"
  15. @interface AS_LoginC () <TT_basevDelegate>
  16. @property (nonatomic, strong) UIScrollView *scrollview;
  17. @property (nonatomic, strong) EamilTFmatchV *xxx_emailTFV;
  18. @property (nonatomic, strong) PassWordSecureBtnV *xxx_passwordV;
  19. @property (nonatomic, strong) UIButton *xxx_logInBtn;
  20. @property (nonatomic, strong) LoginThirdAuthV *xxx_authV;
  21. @property (nonatomic, strong) NSMutableDictionary *thirdLoginParam;
  22. @end
  23. @implementation AS_LoginC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. self.customNavBar.hidden = YES;
  28. self.navigationController.navigationBar.hidden = YES;
  29. self.thirdLoginParam = [[NSMutableDictionary alloc] initWithCapacity:1];
  30. }
  31. - (void)initSubviews{
  32. [super initSubviews];
  33. [self.view addSubview:self.scrollview];
  34. UIView *logNav = [self logNavView];
  35. [self.scrollview addSubview:logNav];
  36. UIImageView *Hi_imgV = [[UIImageView alloc]init];
  37. UIImage *hiImg = [UIImage imageNamed:@"login_HI"];
  38. Hi_imgV.image = hiImg;
  39. Hi_imgV.frame = CGRectMake(20, CGRectGetMaxY(logNav.frame)+30, KScreenWidth-40, hiImg.size.height/hiImg.size.width*(KScreenWidth-40));
  40. [self.scrollview addSubview:Hi_imgV];
  41. [self.scrollview addSubview:self.xxx_emailTFV];
  42. [self.scrollview addSubview:self.xxx_passwordV];
  43. [self.scrollview bringSubviewToFront:self.xxx_emailTFV];
  44. [self.scrollview addSubview:self.xxx_logInBtn];
  45. [self.scrollview addSubview:self.xxx_authV];
  46. UIView *bottomV = [self load_bottom_v];
  47. [self.scrollview addSubview:bottomV];
  48. self.xxx_emailTFV.mj_y = CGRectGetMaxY(Hi_imgV.frame)+35;
  49. self.xxx_passwordV.frame = CGRectFlatMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20);
  50. self.xxx_logInBtn.frame = CGRectMake(20, CGRectGetMaxY(self.xxx_passwordV.frame)+10, KScreenWidth-40, 45);
  51. self.xxx_authV.mj_y = CGRectGetMaxY(self.xxx_logInBtn.frame)+30;
  52. bottomV.mj_y = CGRectGetMaxY(self.xxx_authV.frame)+30;
  53. }
  54. -(void)handle_closeEvent:(UIButton *)btn{
  55. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  56. }
  57. -(void)handle_xxx_logInBtnEvent:(UIButton *)btn{//进行登录操
  58. ///登录的跳转
  59. if (self.xxx_emailTFV.xxx_emailTF.text.length == 0 || ![Current_normalTool xxx_isValidateEmail:self.xxx_emailTFV.xxx_emailTF.text]) {
  60. [self.view makeToast:@"* Please prvide an email address." duration:2 position:CSToastPositionCenter];
  61. return;
  62. }else if(self.xxx_passwordV.xxx_passwordTF.text.length == 0){
  63. [self.view makeToast:@"Please input a password" duration:2 position:CSToastPositionCenter];
  64. return;
  65. }
  66. NSString *urlStr = [NSString stringWithFormat:@"%@V1/integration/customer/token",AS_Server];
  67. NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
  68. params[@"username"] = self.xxx_emailTFV.xxx_emailTF.text;
  69. params[@"password"] = self.xxx_passwordV.xxx_passwordTF.text;
  70. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  71. [ASNetTools xxx_loginWithParam:params success:^(id _Nonnull result) {
  72. [MBProgressHUD hideHUDForView :self.view animated:YES];
  73. @weakify(self)
  74. [self.view makeToast:@"Login Suecess" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  75. @strongify(self)
  76. [self handle_closeEvent:nil];
  77. }];
  78. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  79. [MBProgressHUD hideHUDForView :self.view animated:YES];
  80. [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
  81. }];
  82. /*
  83. [PPNetworkHelper POST:urlStr parameters:params success:^(id responseObject) {
  84. [MBProgressHUD hideHUDForView :self.view animated:YES];
  85. NSDictionary *tmpDic= responseObject;
  86. if([tmpDic[@"status"] intValue] ==1){
  87. NSString *token = MM_str(tmpDic[@"data"]);
  88. //保存 token
  89. [DataUtil setLoginToken:token];
  90. @weakify(self)
  91. [self.view makeToast:@"Login Suecess" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  92. @strongify(self)
  93. [self handle_closeEvent:nil];
  94. }];
  95. }else{
  96. [self.view makeToast:MM_str(tmpDic[@"msg"]) duration:2 position:CSToastPositionCenter];
  97. }
  98. } failure:^(NSError *error) {
  99. [MBProgressHUD hideHUDForView :self.view animated:YES];
  100. if(error == nil){
  101. [self.view makeToast:@"Network request failed" duration:2 position:CSToastPositionCenter];
  102. }else{
  103. NSData *strData = [error userInfo][@"com.alamofire.serialization.response.error.data"];
  104. NSMutableDictionary *temDic =[NSMutableDictionary dictionaryWithDictionary:[PPNetworkHelper too_DataToDic:strData]];
  105. temDic = [UC_CommonmoduleNetWorkTool tt_changeType:temDic];
  106. NSString *errorMsg = @"Network request failed";
  107. if(![Current_normalTool isBlankString:temDic[@"msg"]]){
  108. errorMsg = MM_str(temDic[@"msg"]);
  109. }
  110. [self.view makeToast:errorMsg duration:2 position:CSToastPositionCenter];
  111. }
  112. }];
  113. */
  114. }
  115. //注册页面
  116. -(void)handle_signUpEvent:(UIButton *)btn{
  117. AS_SignUpC *upVC = [[AS_SignUpC alloc]init];
  118. [self.navigationController pushViewController:upVC animated:YES];
  119. }
  120. -(void)handle_forgetBtnEvent:(UIButton *)btn{
  121. LoginForgotC *forgoC = [[LoginForgotC alloc]init];
  122. [self.navigationController pushViewController:forgoC animated:YES];
  123. }
  124. #pragma mark ---- TT_basevDelegate 三方登录授权成功回调 -----
  125. - (void)tengteng_configtaptype:(NSInteger)num data:(id)data {
  126. [self.thirdLoginParam removeAllObjects];
  127. [self.thirdLoginParam addEntriesFromDictionary:(NSDictionary *)data];
  128. NSString *userInfoStr = [self.thirdLoginParam objectForKey:@"userInfo"];
  129. NSDictionary *userInfo = [userInfoStr mj_JSONObject];
  130. NSString *emailStr = userInfo[@"email"];
  131. if ([emailStr validateEmail]) {
  132. [self requestThirdLogin];
  133. } else {//是否绑定过邮箱
  134. [self requestIsBindEmail:userInfo];
  135. }
  136. }
  137. //获取用户是否绑定过邮箱
  138. - (void)requestIsBindEmail:(NSDictionary *)info{
  139. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  140. K_WEAK_SELF;
  141. [ASNetTools.shared postWithPath:userVerifyBindEmailUrl param:@{@"identifier":info[@"identifier"], @"type":self.thirdLoginParam[@"hauth_done"]} success:^(id _Nonnull json) {
  142. K_STRONG_SELF;
  143. [MBProgressHUD hideHUDForView:self.view animated:YES];
  144. ASLoginBindingC *bindVC = [[ASLoginBindingC alloc] init];
  145. bindVC.modalPresentationStyle = UIModalPresentationFullScreen;
  146. K_WEAK_SELF;
  147. bindVC.bindFinishBlock = ^(NSDictionary * _Nonnull bindInfo) {
  148. K_STRONG_SELF;
  149. NSString *userInfoStr = [bindInfo mj_JSONString];
  150. [self.thirdLoginParam setObject:userInfoStr forKey:@"userInfo"];
  151. [self requestThirdLogin];
  152. };
  153. [self presentViewController:bindVC animated:YES completion:nil];
  154. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  155. K_STRONG_SELF;
  156. [MBProgressHUD hideHUDForView:self.view animated:YES];
  157. [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
  158. }];
  159. }
  160. //三方登录接口调用
  161. - (void)requestThirdLogin {
  162. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  163. K_WEAK_SELF;
  164. [ASNetTools.shared formData_postWithPath:userThirdLoginUrl param:self.thirdLoginParam success:^(id _Nonnull json) {
  165. K_STRONG_SELF;
  166. [MBProgressHUD hideHUDForView:self.view animated:YES];
  167. NSString *token = [NSString stringWithFormat:@"Bearer %@", json];
  168. [DataUtil setLoginToken:token];
  169. [ASNetTools.shared updateEngine];
  170. [ASUserInfoManager.shared getInfo];
  171. K_WEAK_SELF;
  172. [self.view makeToast:@"Login Suecess" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  173. K_STRONG_SELF;
  174. [self handle_closeEvent:nil];
  175. }];
  176. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  177. K_STRONG_SELF;
  178. [MBProgressHUD hideHUDForView:self.view animated:YES];
  179. [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
  180. }];
  181. }
  182. #pragma mark - **************** 懒加载 ****************
  183. -(UIView *)logNavView{
  184. IPhoneXHeigh
  185. UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, securitytop_Y)];
  186. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  187. [closeBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateNormal];
  188. [closeBtn addTarget:self action:@selector(handle_closeEvent:) forControlEvents:UIControlEventTouchUpInside];
  189. closeBtn.frame = CGRectMake(20, securitytop_Y-44, 44, 44);
  190. [topView addSubview:closeBtn];
  191. UIImageView *headImg = [[UIImageView alloc]init];
  192. UIImage *bannerImg = [UIImage imageNamed:@"common_headLogo"];
  193. headImg.image = bannerImg ;
  194. headImg.frame = CGRectMake((KScreenWidth- bannerImg.size.width)/2, (IPHONEX ? 44 : 20)+20 , bannerImg.size.width, bannerImg.size.height);
  195. [topView addSubview:headImg];
  196. closeBtn.centerY = topView.centerY;
  197. headImg.centerY = topView.centerY;
  198. return topView;
  199. }
  200. - (UIScrollView *)scrollview {
  201. if (!_scrollview) {
  202. _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  203. }
  204. return _scrollview;
  205. }
  206. -(EamilTFmatchV *)xxx_emailTFV{
  207. if (!_xxx_emailTFV) {
  208. _xxx_emailTFV = [[EamilTFmatchV alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
  209. _xxx_emailTFV.xxx_emailTF.text = @"845600348@qq.com";
  210. }
  211. return _xxx_emailTFV;
  212. }
  213. - (PassWordSecureBtnV *)xxx_passwordV {
  214. if (!_xxx_passwordV) {
  215. _xxx_passwordV = [[PassWordSecureBtnV alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20)];
  216. _xxx_passwordV.xxx_passwordTF.text = @"nuli322103";
  217. }
  218. return _xxx_passwordV;
  219. }
  220. - (UIButton *)xxx_logInBtn {
  221. if (!_xxx_logInBtn) {
  222. _xxx_logInBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  223. [_xxx_logInBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
  224. _xxx_logInBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
  225. [_xxx_logInBtn setTitle:@"LOG IN" forState:UIControlStateNormal];
  226. [_xxx_logInBtn addTarget:self action:@selector(handle_xxx_logInBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  227. _xxx_logInBtn.backgroundColor = ThemeColor;
  228. _xxx_logInBtn.layer.cornerRadius = 4;
  229. _xxx_logInBtn.clipsToBounds = YES;
  230. }
  231. return _xxx_logInBtn;
  232. }
  233. - (LoginThirdAuthV *)xxx_authV {
  234. if (!_xxx_authV) {
  235. _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)];
  236. _xxx_authV.basedelegate = self;
  237. }
  238. return _xxx_authV;
  239. }
  240. -(UIView *)load_bottom_v{
  241. UIView *bottomV = [[UIView alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-40, 46)];
  242. QMUILabel *disLab = [[QMUILabel alloc]init];
  243. disLab.text = @"Don't Have An Account?";
  244. disLab.font = [UIFont fontWithName:Rob_Regular size:12];
  245. [bottomV addSubview:disLab];
  246. UIButton *signUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  247. signUpBtn.backgroundColor = [UIColor clearColor];
  248. NSMutableAttributedString *sinAtr = [[NSMutableAttributedString alloc]initWithString:@"Sign Up" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  249. [signUpBtn setAttributedTitle:sinAtr forState:UIControlStateNormal];
  250. [signUpBtn addTarget:self action:@selector(handle_signUpEvent:) forControlEvents:UIControlEventTouchUpInside];
  251. [signUpBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  252. signUpBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  253. [bottomV addSubview:signUpBtn];
  254. UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  255. forgetBtn.backgroundColor = [UIColor clearColor];
  256. NSMutableAttributedString *forgotAtr = [[NSMutableAttributedString alloc]initWithString:@"Forgot Your Password" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  257. [forgetBtn setAttributedTitle:forgotAtr forState:UIControlStateNormal];
  258. [forgetBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  259. forgetBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  260. [forgetBtn addTarget:self action:@selector(handle_forgetBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  261. [bottomV addSubview:forgetBtn];
  262. [disLab mas_makeConstraints:^(MASConstraintMaker *make) {
  263. make.top.left.mas_equalTo(0);
  264. make.height.mas_equalTo(16);
  265. }];
  266. [signUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  267. make.centerY.equalTo(disLab);
  268. make.left.equalTo(disLab.mas_right).offset(3);
  269. make.height.mas_equalTo(20);
  270. make.width.mas_equalTo(45);
  271. }];
  272. [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  273. make.left.mas_equalTo(0);
  274. make.top.equalTo(disLab.mas_bottom).offset(10);
  275. make.height.mas_equalTo(20);
  276. make.width.mas_equalTo(120);
  277. }];
  278. return bottomV;
  279. }
  280. @end