AS_LoginC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. NSDictionary *param = @{@"identifier":info[@"identifier"],
  141. @"type":self.thirdLoginParam[@"hauth_done"]};
  142. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  143. K_WEAK_SELF;
  144. [ASNetTools.shared formData_postWithPath:userVerifyBindEmailUrl param:param success:^(id _Nonnull json) {
  145. K_STRONG_SELF;
  146. [MBProgressHUD hideHUDForView:self.view animated:YES];
  147. BOOL isShowBind = [json boolValue];
  148. if (isShowBind) {
  149. ASLoginBindingC *bindVC = [[ASLoginBindingC alloc] init];
  150. // bindVC.modalPresentationStyle = UIModalPresentationFullScreen;
  151. K_WEAK_SELF;
  152. bindVC.bindFinishBlock = ^(NSDictionary * _Nonnull bindInfo) {
  153. K_STRONG_SELF;
  154. NSString *userInfoStr = [bindInfo mj_JSONString];
  155. [self.thirdLoginParam setObject:userInfoStr forKey:@"userInfo"];
  156. [self requestThirdLogin];
  157. };
  158. [self.navigationController pushViewController:bindVC animated:YES];
  159. // [self presentViewController:bindVC animated:YES completion:nil];
  160. } else {
  161. NSDictionary *infoDic = @{@"identifier":info[@"identifier"]};
  162. NSString *userInfoStr = [infoDic mj_JSONString];
  163. [self.thirdLoginParam setObject:userInfoStr forKey:@"userInfo"];
  164. [self requestThirdLogin];
  165. }
  166. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  167. K_STRONG_SELF;
  168. [MBProgressHUD hideHUDForView:self.view animated:YES];
  169. [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
  170. }];
  171. }
  172. //三方登录接口调用
  173. - (void)requestThirdLogin {
  174. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  175. K_WEAK_SELF;
  176. [ASNetTools.shared formData_postWithPath:userThirdLoginUrl param:self.thirdLoginParam success:^(id _Nonnull json) {
  177. K_STRONG_SELF;
  178. [MBProgressHUD hideHUDForView:self.view animated:YES];
  179. NSString *token = [NSString stringWithFormat:@"Bearer %@", json];
  180. [DataUtil setLoginToken:token];
  181. [ASNetTools.shared updateEngine];
  182. [ASUserInfoManager.shared getInfo:^{
  183. [ASOneSignalManager setPushApnsTagWithUserInfo];
  184. }];
  185. K_WEAK_SELF;
  186. [self.view makeToast:@"Login Success" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  187. K_STRONG_SELF;
  188. [self handle_closeEvent:nil];
  189. }];
  190. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  191. K_STRONG_SELF;
  192. [MBProgressHUD hideHUDForView:self.view animated:YES];
  193. [self.view makeToast:msg duration:2 position:CSToastPositionCenter];
  194. }];
  195. }
  196. #pragma mark - **************** 懒加载 ****************
  197. -(UIView *)logNavView{
  198. IPhoneXHeigh
  199. UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, securitytop_Y)];
  200. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  201. [closeBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateNormal];
  202. [closeBtn addTarget:self action:@selector(handle_closeEvent:) forControlEvents:UIControlEventTouchUpInside];
  203. closeBtn.frame = CGRectMake(20, securitytop_Y-44, 44, 44);
  204. [topView addSubview:closeBtn];
  205. UIImageView *headImg = [[UIImageView alloc]init];
  206. UIImage *bannerImg = [UIImage imageNamed:@"common_headLogo"];
  207. headImg.image = bannerImg ;
  208. headImg.frame = CGRectMake((KScreenWidth- bannerImg.size.width)/2, (IPHONEX ? 44 : 20)+20 , bannerImg.size.width, bannerImg.size.height);
  209. [topView addSubview:headImg];
  210. closeBtn.centerY = topView.centerY;
  211. headImg.centerY = topView.centerY;
  212. return topView;
  213. }
  214. - (UIScrollView *)scrollview {
  215. if (!_scrollview) {
  216. _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  217. }
  218. return _scrollview;
  219. }
  220. -(EamilTFmatchV *)xxx_emailTFV{
  221. if (!_xxx_emailTFV) {
  222. _xxx_emailTFV = [[EamilTFmatchV alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
  223. _xxx_emailTFV.xxx_emailTF.text = @"845600348@qq.com";
  224. }
  225. return _xxx_emailTFV;
  226. }
  227. - (PassWordSecureBtnV *)xxx_passwordV {
  228. if (!_xxx_passwordV) {
  229. _xxx_passwordV = [[PassWordSecureBtnV alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20)];
  230. _xxx_passwordV.xxx_passwordTF.text = @"nuli322103";
  231. }
  232. return _xxx_passwordV;
  233. }
  234. - (UIButton *)xxx_logInBtn {
  235. if (!_xxx_logInBtn) {
  236. _xxx_logInBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  237. [_xxx_logInBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
  238. _xxx_logInBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
  239. [_xxx_logInBtn setTitle:@"LOG IN" forState:UIControlStateNormal];
  240. [_xxx_logInBtn addTarget:self action:@selector(handle_xxx_logInBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  241. _xxx_logInBtn.backgroundColor = ThemeColor;
  242. _xxx_logInBtn.layer.cornerRadius = 4;
  243. _xxx_logInBtn.clipsToBounds = YES;
  244. }
  245. return _xxx_logInBtn;
  246. }
  247. - (LoginThirdAuthV *)xxx_authV {
  248. if (!_xxx_authV) {
  249. _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)];
  250. _xxx_authV.basedelegate = self;
  251. }
  252. return _xxx_authV;
  253. }
  254. -(UIView *)load_bottom_v{
  255. UIView *bottomV = [[UIView alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-40, 46)];
  256. QMUILabel *disLab = [[QMUILabel alloc]init];
  257. disLab.text = @"Don't Have An Account?";
  258. disLab.font = [UIFont fontWithName:Rob_Regular size:12];
  259. [bottomV addSubview:disLab];
  260. UIButton *signUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  261. signUpBtn.backgroundColor = [UIColor clearColor];
  262. NSMutableAttributedString *sinAtr = [[NSMutableAttributedString alloc]initWithString:@"Sign Up" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  263. [signUpBtn setAttributedTitle:sinAtr forState:UIControlStateNormal];
  264. [signUpBtn addTarget:self action:@selector(handle_signUpEvent:) forControlEvents:UIControlEventTouchUpInside];
  265. [signUpBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  266. signUpBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  267. [bottomV addSubview:signUpBtn];
  268. UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  269. forgetBtn.backgroundColor = [UIColor clearColor];
  270. NSMutableAttributedString *forgotAtr = [[NSMutableAttributedString alloc]initWithString:@"Forgot Your Password" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  271. [forgetBtn setAttributedTitle:forgotAtr forState:UIControlStateNormal];
  272. [forgetBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  273. forgetBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  274. [forgetBtn addTarget:self action:@selector(handle_forgetBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  275. [bottomV addSubview:forgetBtn];
  276. [disLab mas_makeConstraints:^(MASConstraintMaker *make) {
  277. make.top.left.mas_equalTo(0);
  278. make.height.mas_equalTo(16);
  279. }];
  280. [signUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  281. make.centerY.equalTo(disLab);
  282. make.left.equalTo(disLab.mas_right).offset(3);
  283. make.height.mas_equalTo(20);
  284. make.width.mas_equalTo(45);
  285. }];
  286. [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  287. make.left.mas_equalTo(0);
  288. make.top.equalTo(disLab.mas_bottom).offset(10);
  289. make.height.mas_equalTo(20);
  290. make.width.mas_equalTo(120);
  291. }];
  292. return bottomV;
  293. }
  294. @end