| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- //
- // MOSetPasswordVC.m
- // MiMoLive
- //
- // Created by SuperC on 2023/10/31.
- //
- #import "MOSetPasswordVC.h"
- #import "NSString+YYAdd.h"
- #import "MOWebViewController.h"
- #import "MOAccountSecurityVC.h"
- #import "UITextField+CustomClearButton.h"
- @interface MOSetPasswordVC ()
- @property (weak, nonatomic) IBOutlet UILabel *topTipLab;
- @property (weak, nonatomic) IBOutlet UILabel *topTipContentLab;
- @property (weak, nonatomic) IBOutlet UIView *textBgView;
- @property (weak, nonatomic) IBOutlet UITextField *textField;
- @property (weak, nonatomic) IBOutlet UIButton *eyeButton;
- @property (weak, nonatomic) IBOutlet UIView *repeatTextBgView;
- @property (weak, nonatomic) IBOutlet UITextField *repeatTextField;
- @property (weak, nonatomic) IBOutlet UIButton *repeatEyeButton;
- @property (weak, nonatomic) IBOutlet UIButton *submitBtn;
- @end
- @implementation MOSetPasswordVC
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:animated];
-
- [self mo_v2_setNavLeftItemWithImage:[UIImage imageNamed:@"v_2_icon_new_back_black"] andBackgroundImg:nil AndBgColor:nil];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = NSLocalString(@"mimo_set_psw_title");
-
- [self setupUI];
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
-
- [self.textBgView setupGradientLayerWithView:self.textBgView
- startColor:[MOTools colorWithHexString:@"#FFFFFF"]
- endColor:[MOTools colorWithHexString:@"#FFFFFF"]
- layerName:@"gradientLayer"
- startPoint:(CGPoint) { 0.5, 0 }
- endPoint:(CGPoint){0.5, 1}];
-
- [self.repeatTextBgView setupGradientLayerWithView:self.repeatTextBgView
- startColor:[MOTools colorWithHexString:@"#FFFFFF"]
- endColor:[MOTools colorWithHexString:@"#FFFFFF"]
- layerName:@"gradientLayer"
- startPoint:(CGPoint) { 0.5, 0 }
- endPoint:(CGPoint){0.5, 1}];
- }
- - (void)setupUI{
-
- self.view.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
-
- self.topTipLab.text = NSLocalString(@"mimo_set_psw_set_top_tip");
- self.topTipLab.font = [MOTextTools regularFont:14];
- self.topTipLab.textColor = kBaseTextColor_1;
-
- self.topTipContentLab.text = NSLocalString(@"mimo_set_psw_set_top_contant_tip");
- self.topTipContentLab.textColor = kBaseTextColor_3;
- self.topTipContentLab.font = [MOTextTools regularFont:14];
-
- self.textBgView.layer.cornerRadius = 12.0;
- self.textBgView.layer.masksToBounds = YES;
- self.textBgView.layer.borderColor = [MOTools colorWithHexString:@"#FFFFFF"].CGColor;
- self.textBgView.layer.borderWidth = 1;
-
- [self.textField setFont:[MOTextTools poppinsMediumFont:18]];
- self.textField.textColor = [MOTools colorWithHexString:@"#111111"];
- // self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.textField.clearButtonMode = UITextFieldViewModeNever;
- UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
- [self.textField enableCustomClearButtonWithImage:clearIcon];
- self.textField.secureTextEntry = YES;
- NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_new_password") attributes:@{
- NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
- NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
- }];
- self.textField.attributedPlaceholder = placeholderString;
- [self.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
-
- self.repeatTextBgView.layer.cornerRadius = 12.0;
- self.repeatTextBgView.layer.masksToBounds = YES;
- self.repeatTextBgView.layer.borderColor = [MOTools colorWithHexString:@"#FFFFFF"].CGColor;
- self.repeatTextBgView.layer.borderWidth = 1;
-
- [self.repeatTextField setFont:[MOTextTools poppinsMediumFont:18]];
- self.repeatTextField.textColor = [MOTools colorWithHexString:@"#111111"];
- // self.repeatTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
- self.repeatTextField.clearButtonMode = UITextFieldViewModeNever;
- [self.repeatTextField enableCustomClearButtonWithImage:clearIcon];
- self.repeatTextField.secureTextEntry = YES;
- NSMutableAttributedString *placeholderString2 = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_new_password_again") attributes:@{
- NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
- NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
- }];
- self.repeatTextField.attributedPlaceholder = placeholderString2;
- [self.repeatTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
-
- [self.submitBtn setTitle:NSLocalString(@"mimo_password_confirm") forState:UIControlStateNormal];
- NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
- UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 20.0 * 2), 48.0) Colors:loginColorArr GradientType:0];
- [self.submitBtn setBackgroundImage:loginImage forState:UIControlStateNormal];
- self.submitBtn.layer.cornerRadius = 12;
- self.submitBtn.layer.masksToBounds = YES;
- self.submitBtn.titleLabel.font = [MOTextTools mediumFont:16];
- [self.submitBtn setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
- self.submitBtn.alpha = 0.5;
- }
- - (void)textFieldDidChange:(UITextField *)textField {
- BOOL hasInputPwd = self.textField.text.length > 0;
- BOOL hasRepeatPwd = self.repeatTextField.text.length > 0;
-
- self.submitBtn.alpha = (hasInputPwd && hasRepeatPwd) ? 1.0 : 0.5;
- }
- - (IBAction)pswShowBtnClick:(UIButton *)sender {
- sender.selected = !sender.selected;
-
- if ([sender isEqual:self.eyeButton]) {
- self.textField.secureTextEntry = !sender.selected;
- } else if ([sender isEqual:self.repeatEyeButton]) {
- self.repeatTextField.secureTextEntry = !sender.selected;
- }
- }
- - (IBAction)submitBtnClick:(id)sender {
-
- if(self.textField.text.length == 0)
- {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_password_empty")];
- return;
- }
-
- MOMeDataInfo *userInfoData = (MOMeDataInfo *)[[MODataCache sharedYYCache] objectForKey:kMineUserInfo];
-
- NSString *code = self.code;
- NSString *num = self.num;
-
- if(code.length == 0){
- code = userInfoData.userMobile.code;
- }
-
- if(num.length == 0){
- num = userInfoData.userMobile.num;
- }
-
- if(self.textField.text.length < 8 || self.textField.text.length > 20){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_set_top_contant_tip")];
- return;
- }
-
- // if(![MOSetPasswordVC containsLetterAndNumber:self.textField.text]){
- // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_set_psw_set_top_contant_tip")];
- // return;
- // }
-
- if([self.textField.text rangeOfString:@" "].location != NSNotFound){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_psw_no_spacing")];
- return;
- }
-
- if (![self.textField.text isEqualToString:self.repeatTextField.text]) {
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_psw_not_same")];
- return;
- }
-
- NSString *pswStr = [self.textField.text md5String];
-
- //前置界面有做判空, 这里就不做判空了
- NSDictionary *mobileDict = @{@"code":code,
- @"num":num};
-
- //TODO: 请求参数需要修改
- WEAKSELF
- NSDictionary *dict = @{@"code":self.codeString,
- @"pwd":pswStr,
- @"mobile":mobileDict};
-
- [kHttpManager toResetThePassword2WithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
- if(kCode_Success){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_common_success")];
- [self performSelector:@selector(backToRootVC) withObject:nil afterDelay:1.5];
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- ///判断输入字符串是否同时包含字母和数字
- + (BOOL)containsLetterAndNumber:(NSString *)input {
- // 创建匹配字母的正则表达式
- NSRegularExpression *letterRegex = [NSRegularExpression regularExpressionWithPattern:@".*[a-zA-Z]+.*" options:0 error:NULL];
- // 创建匹配数字的正则表达式
- NSRegularExpression *numberRegex = [NSRegularExpression regularExpressionWithPattern:@".*[0-9]+.*" options:0 error:NULL];
-
- // 判断输入字符串中是否包含字母
- BOOL containsLetter = [letterRegex numberOfMatchesInString:input options:0 range:NSMakeRange(0, input.length)] > 0;
- // 判断输入字符串中是否包含数字
- BOOL containsNumber = [numberRegex numberOfMatchesInString:input options:0 range:NSMakeRange(0, input.length)] > 0;
-
- // 判断是否同时包含字母和数字
- return containsLetter && containsNumber;
- }
- - (void)backToRootVC{
-
- // 获取当前导航控制器的所有视图控制器
- NSArray *viewControllers = self.navigationController.viewControllers;
- for (UIViewController *vc in viewControllers) {
-
- //优先判断是否有网页跳转
- if ([vc isKindOfClass:[MOWebViewController class]]) {
- // 返回到 MOAccountSecurityVC
- [self.navigationController popToViewController:vc animated:YES];
- return;
- }
-
- // 判断是否是 MOAccountSecurityVC 类型
- if ([vc isKindOfClass:[MOAccountSecurityVC class]]) {
- // 返回到 MOAccountSecurityVC
- MOAccountSecurityVC *theVc = (MOAccountSecurityVC *)vc;
- [theVc toGetTheSecurityInfo];
- [self.navigationController popToViewController:vc animated:YES];
- return;
- }
- }
-
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- @end
|