MOSetPasswordVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // MOSetPasswordVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/31.
  6. //
  7. #import "MOSetPasswordVC.h"
  8. #import "NSString+YYAdd.h"
  9. #import "MOWebViewController.h"
  10. #import "MOAccountSecurityVC.h"
  11. #import "UITextField+CustomClearButton.h"
  12. @interface MOSetPasswordVC ()
  13. @property (weak, nonatomic) IBOutlet UILabel *topTipLab;
  14. @property (weak, nonatomic) IBOutlet UILabel *topTipContentLab;
  15. @property (weak, nonatomic) IBOutlet UIView *textBgView;
  16. @property (weak, nonatomic) IBOutlet UITextField *textField;
  17. @property (weak, nonatomic) IBOutlet UIButton *eyeButton;
  18. @property (weak, nonatomic) IBOutlet UIView *repeatTextBgView;
  19. @property (weak, nonatomic) IBOutlet UITextField *repeatTextField;
  20. @property (weak, nonatomic) IBOutlet UIButton *repeatEyeButton;
  21. @property (weak, nonatomic) IBOutlet UIButton *submitBtn;
  22. @end
  23. @implementation MOSetPasswordVC
  24. - (void)viewWillAppear:(BOOL)animated{
  25. [super viewWillAppear:animated];
  26. [self.navigationController setNavigationBarHidden:NO animated:animated];
  27. [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.navigationItem.title = NSLocalString(@"mimo_set_psw_title");
  32. [self setupUI];
  33. }
  34. - (void)viewWillLayoutSubviews {
  35. [super viewWillLayoutSubviews];
  36. [self.textBgView setupGradientLayerWithView:self.textBgView
  37. startColor:[MOTools colorWithHexString:@"#FFFFFF"]
  38. endColor:[MOTools colorWithHexString:@"#FFFFFF"]
  39. layerName:@"gradientLayer"
  40. startPoint:(CGPoint) { 0.5, 0 }
  41. endPoint:(CGPoint){0.5, 1}];
  42. [self.repeatTextBgView setupGradientLayerWithView:self.repeatTextBgView
  43. startColor:[MOTools colorWithHexString:@"#FFFFFF"]
  44. endColor:[MOTools colorWithHexString:@"#FFFFFF"]
  45. layerName:@"gradientLayer"
  46. startPoint:(CGPoint) { 0.5, 0 }
  47. endPoint:(CGPoint){0.5, 1}];
  48. }
  49. - (void)setupUI{
  50. self.view.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
  51. self.topTipLab.text = NSLocalString(@"mimo_set_psw_set_top_tip");
  52. self.topTipLab.font = [MOTextTools regularFont:14];
  53. self.topTipLab.textColor = kBaseTextColor_1;
  54. self.topTipContentLab.text = NSLocalString(@"mimo_set_psw_set_top_contant_tip");
  55. self.topTipContentLab.textColor = kBaseTextColor_3;
  56. self.topTipContentLab.font = [MOTextTools regularFont:14];
  57. self.textBgView.layer.cornerRadius = 12.0;
  58. self.textBgView.layer.masksToBounds = YES;
  59. self.textBgView.layer.borderColor = [MOTools colorWithHexString:@"#FFFFFF"].CGColor;
  60. self.textBgView.layer.borderWidth = 1;
  61. [self.textField setFont:[MOTextTools poppinsMediumFont:18]];
  62. self.textField.textColor = [MOTools colorWithHexString:@"#111111"];
  63. // self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  64. self.textField.clearButtonMode = UITextFieldViewModeNever;
  65. UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
  66. [self.textField enableCustomClearButtonWithImage:clearIcon];
  67. self.textField.secureTextEntry = YES;
  68. NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_new_password") attributes:@{
  69. NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
  70. NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
  71. }];
  72. self.textField.attributedPlaceholder = placeholderString;
  73. [self.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  74. self.repeatTextBgView.layer.cornerRadius = 12.0;
  75. self.repeatTextBgView.layer.masksToBounds = YES;
  76. self.repeatTextBgView.layer.borderColor = [MOTools colorWithHexString:@"#FFFFFF"].CGColor;
  77. self.repeatTextBgView.layer.borderWidth = 1;
  78. [self.repeatTextField setFont:[MOTextTools poppinsMediumFont:18]];
  79. self.repeatTextField.textColor = [MOTools colorWithHexString:@"#111111"];
  80. // self.repeatTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  81. self.repeatTextField.clearButtonMode = UITextFieldViewModeNever;
  82. [self.repeatTextField enableCustomClearButtonWithImage:clearIcon];
  83. self.repeatTextField.secureTextEntry = YES;
  84. NSMutableAttributedString *placeholderString2 = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_new_password_again") attributes:@{
  85. NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
  86. NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
  87. }];
  88. self.repeatTextField.attributedPlaceholder = placeholderString2;
  89. [self.repeatTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  90. [self.submitBtn setTitle:NSLocalString(@"mimo_password_confirm") forState:UIControlStateNormal];
  91. NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
  92. UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 20.0 * 2), 48.0) Colors:loginColorArr GradientType:0];
  93. [self.submitBtn setBackgroundImage:loginImage forState:UIControlStateNormal];
  94. self.submitBtn.layer.cornerRadius = 12;
  95. self.submitBtn.layer.masksToBounds = YES;
  96. self.submitBtn.titleLabel.font = [MOTextTools mediumFont:16];
  97. [self.submitBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  98. self.submitBtn.alpha = 0.5;
  99. }
  100. - (void)textFieldDidChange:(UITextField *)textField {
  101. BOOL hasInputPwd = self.textField.text.length > 0;
  102. BOOL hasRepeatPwd = self.repeatTextField.text.length > 0;
  103. self.submitBtn.alpha = (hasInputPwd && hasRepeatPwd) ? 1.0 : 0.5;
  104. }
  105. - (IBAction)pswShowBtnClick:(UIButton *)sender {
  106. sender.selected = !sender.selected;
  107. if ([sender isEqual:self.eyeButton]) {
  108. self.textField.secureTextEntry = !sender.selected;
  109. } else if ([sender isEqual:self.repeatEyeButton]) {
  110. self.repeatTextField.secureTextEntry = !sender.selected;
  111. }
  112. }
  113. - (IBAction)submitBtnClick:(id)sender {
  114. if(self.textField.text.length == 0)
  115. {
  116. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_password_empty")];
  117. return;
  118. }
  119. MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
  120. NSString *code = self.code;
  121. NSString *num = self.num;
  122. if(code.length == 0){
  123. code = userInfoData.userMobile.code;
  124. }
  125. if(num.length == 0){
  126. num = userInfoData.userMobile.num;
  127. }
  128. if(self.textField.text.length < 8 || self.textField.text.length > 20){
  129. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_set_top_contant_tip")];
  130. return;
  131. }
  132. // if(![MOSetPasswordVC containsLetterAndNumber:self.textField.text]){
  133. // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_set_top_contant_tip")];
  134. // return;
  135. // }
  136. if([self.textField.text rangeOfString:@" "].location != NSNotFound){
  137. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_psw_no_spacing")];
  138. return;
  139. }
  140. if (![self.textField.text isEqualToString:self.repeatTextField.text]) {
  141. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_psw_not_same")];
  142. return;
  143. }
  144. NSString *pswStr = [self.textField.text md5String];
  145. //前置界面有做判空, 这里就不做判空了
  146. NSDictionary *mobileDict = @{@"code":code,
  147. @"num":num};
  148. //TODO: 请求参数需要修改
  149. WEAKSELF
  150. NSDictionary *dict = @{@"code":self.codeString,
  151. @"pwd":pswStr,
  152. @"mobile":mobileDict};
  153. [kHttpManager toResetThePassword2WithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  154. __strong typeof(weakSelf) self = weakSelf;
  155. if(kCode_Success){
  156. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_success")];
  157. [self performSelector:@selector(backToRootVC) withObject:nil afterDelay:1.5];
  158. }
  159. else{
  160. kShowNetError(data)
  161. }
  162. }];
  163. }
  164. ///判断输入字符串是否同时包含字母和数字
  165. + (BOOL)containsLetterAndNumber:(NSString *)input {
  166. // 创建匹配字母的正则表达式
  167. NSRegularExpression *letterRegex = [NSRegularExpression regularExpressionWithPattern:@".*[a-zA-Z]+.*" options:0 error:NULL];
  168. // 创建匹配数字的正则表达式
  169. NSRegularExpression *numberRegex = [NSRegularExpression regularExpressionWithPattern:@".*[0-9]+.*" options:0 error:NULL];
  170. // 判断输入字符串中是否包含字母
  171. BOOL containsLetter = [letterRegex numberOfMatchesInString:input options:0 range:NSMakeRange(0, input.length)] > 0;
  172. // 判断输入字符串中是否包含数字
  173. BOOL containsNumber = [numberRegex numberOfMatchesInString:input options:0 range:NSMakeRange(0, input.length)] > 0;
  174. // 判断是否同时包含字母和数字
  175. return containsLetter && containsNumber;
  176. }
  177. - (void)backToRootVC{
  178. // 获取当前导航控制器的所有视图控制器
  179. NSArray *viewControllers = self.navigationController.viewControllers;
  180. for (UIViewController *vc in viewControllers) {
  181. //优先判断是否有网页跳转
  182. if ([vc isKindOfClass:[MOWebViewController class]]) {
  183. // 返回到 MOAccountSecurityVC
  184. [self.navigationController popToViewController:vc animated:YES];
  185. return;
  186. }
  187. // 判断是否是 MOAccountSecurityVC 类型
  188. if ([vc isKindOfClass:[MOAccountSecurityVC class]]) {
  189. // 返回到 MOAccountSecurityVC
  190. MOAccountSecurityVC *theVc = (MOAccountSecurityVC *)vc;
  191. [theVc toGetTheSecurityInfo];
  192. [self.navigationController popToViewController:vc animated:YES];
  193. return;
  194. }
  195. }
  196. [self.navigationController popToRootViewControllerAnimated:YES];
  197. }
  198. @end