AS_LoginC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "AS_ForgotC.h"
  14. @interface AS_LoginC ()
  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. AS_ForgotC *forgoC = [[AS_ForgotC alloc]init];
  119. [self.navigationController pushViewController:forgoC animated:YES];
  120. }
  121. #pragma mark - **************** 懒加载 ****************
  122. -(UIView *)logNavView{
  123. IPhoneXHeigh
  124. UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, securitytop_Y)];
  125. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  126. [closeBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateNormal];
  127. [closeBtn addTarget:self action:@selector(handle_closeEvent:) forControlEvents:UIControlEventTouchUpInside];
  128. closeBtn.frame = CGRectMake(20, securitytop_Y-44, 44, 44);
  129. [topView addSubview:closeBtn];
  130. UIImageView *headImg = [[UIImageView alloc]init];
  131. UIImage *bannerImg = [UIImage imageNamed:@"common_headLogo"];
  132. headImg.image = bannerImg ;
  133. headImg.frame = CGRectMake((KScreenWidth- bannerImg.size.width)/2, (IPHONEX ? 44 : 20)+20 , bannerImg.size.width, bannerImg.size.height);
  134. [topView addSubview:headImg];
  135. closeBtn.centerY = topView.centerY;
  136. headImg.centerY = topView.centerY;
  137. return topView;
  138. }
  139. - (UIScrollView *)scrollview {
  140. if (!_scrollview) {
  141. _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  142. }
  143. return _scrollview;
  144. }
  145. -(EamilTFmatchV *)xxx_emailTFV{
  146. if (!_xxx_emailTFV) {
  147. _xxx_emailTFV = [[EamilTFmatchV alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
  148. }
  149. return _xxx_emailTFV;
  150. }
  151. - (PassWordSecureBtnV *)xxx_passwordV {
  152. if (!_xxx_passwordV) {
  153. _xxx_passwordV = [[PassWordSecureBtnV alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20)];
  154. }
  155. return _xxx_passwordV;
  156. }
  157. - (UIButton *)xxx_logInBtn {
  158. if (!_xxx_logInBtn) {
  159. _xxx_logInBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  160. [_xxx_logInBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
  161. _xxx_logInBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
  162. [_xxx_logInBtn setTitle:@"LOG IN" forState:UIControlStateNormal];
  163. [_xxx_logInBtn addTarget:self action:@selector(handle_xxx_logInBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  164. _xxx_logInBtn.backgroundColor = ThemeColor;
  165. _xxx_logInBtn.layer.cornerRadius = 4;
  166. _xxx_logInBtn.clipsToBounds = YES;
  167. }
  168. return _xxx_logInBtn;
  169. }
  170. - (LoginThirdAuthV *)xxx_authV {
  171. if (!_xxx_authV) {
  172. _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)];
  173. }
  174. return _xxx_authV;
  175. }
  176. -(UIView *)load_bottom_v{
  177. UIView *bottomV = [[UIView alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-40, 32)];
  178. QMUILabel *disLab = [[QMUILabel alloc]init];
  179. disLab.text = @"Don't Have An Account?";
  180. disLab.font = [UIFont fontWithName:Rob_Regular size:12];
  181. [bottomV addSubview:disLab];
  182. UIButton *signUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  183. signUpBtn.backgroundColor = [UIColor clearColor];
  184. NSMutableAttributedString *sinAtr = [[NSMutableAttributedString alloc]initWithString:@"Sign Up" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  185. [signUpBtn setAttributedTitle:sinAtr forState:UIControlStateNormal];
  186. [signUpBtn addTarget:self action:@selector(handle_signUpEvent:) forControlEvents:UIControlEventTouchUpInside];
  187. [signUpBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  188. signUpBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  189. [bottomV addSubview:signUpBtn];
  190. UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  191. forgetBtn.backgroundColor = [UIColor clearColor];
  192. NSMutableAttributedString *forgotAtr = [[NSMutableAttributedString alloc]initWithString:@"Forgot Your Password" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  193. [forgetBtn setAttributedTitle:forgotAtr forState:UIControlStateNormal];
  194. [forgetBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  195. forgetBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  196. [forgetBtn addTarget:self action:@selector(handle_forgetBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  197. [bottomV addSubview:forgetBtn];
  198. [disLab mas_makeConstraints:^(MASConstraintMaker *make) {
  199. make.top.left.mas_equalTo(0);
  200. make.height.mas_equalTo(16);
  201. }];
  202. [signUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  203. make.centerY.equalTo(disLab);
  204. make.left.equalTo(disLab.mas_right).offset(3);
  205. make.height.mas_equalTo(20);
  206. make.width.mas_equalTo(45);
  207. }];
  208. [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  209. make.left.mas_equalTo(0);
  210. make.top.equalTo(disLab.mas_bottom).offset(10);
  211. make.height.mas_equalTo(15);
  212. make.width.mas_equalTo(120);
  213. }];
  214. return bottomV;
  215. }
  216. @end