AS_LoginC.m 12 KB

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