AS_LoginC.m 14 KB

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