AS_LoginC.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. [PPNetworkHelper POST:urlStr parameters:params success:^(id responseObject) {
  69. [MBProgressHUD hideHUDForView :self.view animated:YES];
  70. NSDictionary *tmpDic= responseObject;
  71. if([tmpDic[@"status"] intValue] ==1){
  72. NSString *token = MM_str(tmpDic[@"data"]);
  73. //保存 token
  74. [DataUtil setLoginToken:token];
  75. @weakify(self)
  76. [self.view makeToast:@"Login Suecess" duration:2 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
  77. @strongify(self)
  78. [self handle_closeEvent:nil];
  79. }];
  80. }else{
  81. [self.view makeToast:MM_str(tmpDic[@"msg"]) duration:2 position:CSToastPositionCenter];
  82. }
  83. } failure:^(NSError *error) {
  84. [MBProgressHUD hideHUDForView :self.view animated:YES];
  85. if(error == nil){
  86. [self.view makeToast:@"Network request failed" duration:2 position:CSToastPositionCenter];
  87. }else{
  88. NSData *strData = [error userInfo][@"com.alamofire.serialization.response.error.data"];
  89. NSMutableDictionary *temDic =[NSMutableDictionary dictionaryWithDictionary:[PPNetworkHelper too_DataToDic:strData]];
  90. temDic = [UC_CommonmoduleNetWorkTool tt_changeType:temDic];
  91. NSString *errorMsg = @"Network request failed";
  92. if(![Current_normalTool isBlankString:temDic[@"msg"]]){
  93. errorMsg = MM_str(temDic[@"msg"]);
  94. }
  95. [self.view makeToast:errorMsg duration:2 position:CSToastPositionCenter];
  96. }
  97. }];
  98. }
  99. //注册页面
  100. -(void)handle_signUpEvent:(UIButton *)btn{
  101. AS_SignUpC *upVC = [[AS_SignUpC alloc]init];
  102. [self.navigationController pushViewController:upVC animated:YES];
  103. }
  104. -(void)handle_forgetBtnEvent:(UIButton *)btn{
  105. AS_ForgotC *forgoC = [[AS_ForgotC alloc]init];
  106. [self.navigationController pushViewController:forgoC animated:YES];
  107. }
  108. #pragma mark - **************** 懒加载 ****************
  109. -(UIView *)logNavView{
  110. IPhoneXHeigh
  111. UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, securitytop_Y)];
  112. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  113. [closeBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateNormal];
  114. [closeBtn addTarget:self action:@selector(handle_closeEvent:) forControlEvents:UIControlEventTouchUpInside];
  115. closeBtn.frame = CGRectMake(20, securitytop_Y-44, 44, 44);
  116. [topView addSubview:closeBtn];
  117. UIImageView *headImg = [[UIImageView alloc]init];
  118. UIImage *bannerImg = [UIImage imageNamed:@"common_headLogo"];
  119. headImg.image = bannerImg ;
  120. headImg.frame = CGRectMake((KScreenWidth- bannerImg.size.width)/2, (IPHONEX ? 44 : 20)+20 , bannerImg.size.width, bannerImg.size.height);
  121. [topView addSubview:headImg];
  122. closeBtn.centerY = topView.centerY;
  123. headImg.centerY = topView.centerY;
  124. return topView;
  125. }
  126. - (UIScrollView *)scrollview {
  127. if (!_scrollview) {
  128. _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  129. }
  130. return _scrollview;
  131. }
  132. -(EamilTFmatchV *)xxx_emailTFV{
  133. if (!_xxx_emailTFV) {
  134. _xxx_emailTFV = [[EamilTFmatchV alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
  135. }
  136. return _xxx_emailTFV;
  137. }
  138. - (PassWordSecureBtnV *)xxx_passwordV {
  139. if (!_xxx_passwordV) {
  140. _xxx_passwordV = [[PassWordSecureBtnV alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.xxx_emailTFV.frame)+30, KScreenWidth-40, 50+20)];
  141. }
  142. return _xxx_passwordV;
  143. }
  144. - (UIButton *)xxx_logInBtn {
  145. if (!_xxx_logInBtn) {
  146. _xxx_logInBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  147. [_xxx_logInBtn setTitleColor:[UIColor colorWithHexString:@"#000000"] forState:UIControlStateNormal];
  148. _xxx_logInBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
  149. [_xxx_logInBtn setTitle:@"LOG IN" forState:UIControlStateNormal];
  150. [_xxx_logInBtn addTarget:self action:@selector(handle_xxx_logInBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  151. _xxx_logInBtn.backgroundColor = ThemeColor;
  152. _xxx_logInBtn.layer.cornerRadius = 4;
  153. _xxx_logInBtn.clipsToBounds = YES;
  154. }
  155. return _xxx_logInBtn;
  156. }
  157. - (LoginThirdAuthV *)xxx_authV {
  158. if (!_xxx_authV) {
  159. _xxx_authV = [[LoginThirdAuthV alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 15+20+(36+10)*3)];
  160. }
  161. return _xxx_authV;
  162. }
  163. -(UIView *)load_bottom_v{
  164. UIView *bottomV = [[UIView alloc]initWithFrame:CGRectMake(20, 0, KScreenWidth-40, 32)];
  165. QMUILabel *disLab = [[QMUILabel alloc]init];
  166. disLab.text = @"Don't Have An Account?";
  167. disLab.font = [UIFont fontWithName:Rob_Regular size:12];
  168. [bottomV addSubview:disLab];
  169. UIButton *signUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  170. signUpBtn.backgroundColor = [UIColor clearColor];
  171. NSMutableAttributedString *sinAtr = [[NSMutableAttributedString alloc]initWithString:@"Sign Up" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  172. [signUpBtn setAttributedTitle:sinAtr forState:UIControlStateNormal];
  173. [signUpBtn addTarget:self action:@selector(handle_signUpEvent:) forControlEvents:UIControlEventTouchUpInside];
  174. [signUpBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  175. signUpBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  176. [bottomV addSubview:signUpBtn];
  177. UIButton *forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  178. forgetBtn.backgroundColor = [UIColor clearColor];
  179. NSMutableAttributedString *forgotAtr = [[NSMutableAttributedString alloc]initWithString:@"Forgot Your Password" attributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
  180. [forgetBtn setAttributedTitle:forgotAtr forState:UIControlStateNormal];
  181. [forgetBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
  182. forgetBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  183. [forgetBtn addTarget:self action:@selector(handle_forgetBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  184. [bottomV addSubview:forgetBtn];
  185. [disLab mas_makeConstraints:^(MASConstraintMaker *make) {
  186. make.top.left.mas_equalTo(0);
  187. make.height.mas_equalTo(16);
  188. }];
  189. [signUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.centerY.equalTo(disLab);
  191. make.left.equalTo(disLab.mas_right).offset(3);
  192. make.height.mas_equalTo(20);
  193. make.width.mas_equalTo(45);
  194. }];
  195. [forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.left.mas_equalTo(0);
  197. make.top.equalTo(disLab.mas_bottom).offset(10);
  198. make.height.mas_equalTo(15);
  199. make.width.mas_equalTo(120);
  200. }];
  201. return bottomV;
  202. }
  203. @end