203 lines
7.5 KiB
Objective-C
203 lines
7.5 KiB
Objective-C
//
|
|
// YMForgetPwdViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by XY on 2023/2/14.
|
|
//
|
|
|
|
#import "XPForgetPwdViewController.h"
|
|
#import <Masonry.h>
|
|
#import "YUMIMacroUitls.h"
|
|
#import <ReactiveObjC.h>
|
|
|
|
#import "XPLoginInputView.h"
|
|
|
|
#import "LoginForgetPasswordPresent.h"
|
|
#import "LoginForgetPasswordProtocol.h"
|
|
#import "XPLoginAraeViewController.h"
|
|
|
|
@interface XPForgetPwdViewController ()<XPLoginInputViewDelegate, LoginForgetPasswordProtocol, XPLoginAraeViewControllerDelegate>
|
|
|
|
/// 标题
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
/// 手机号输入框
|
|
@property (nonatomic, strong) XPLoginInputView *phoneInputView;
|
|
/// 验证码输入框
|
|
@property (nonatomic, strong) XPLoginInputView *codeInputView;
|
|
/// 密码输入框
|
|
@property (nonatomic, strong) XPLoginInputView *pwdInputView;
|
|
/// 确定按钮
|
|
@property (nonatomic, strong) UIButton *sureBtn;
|
|
@property (nonatomic,copy) NSString *phoneAreaCode;
|
|
|
|
@end
|
|
|
|
@implementation XPForgetPwdViewController
|
|
|
|
- (LoginForgetPasswordPresent *)createPresenter {
|
|
return [[LoginForgetPasswordPresent alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
self.phoneAreaCode = @"852";
|
|
self.needEffect = YES;
|
|
self.needBack = YES;
|
|
[super viewDidLoad];
|
|
[self createUI];
|
|
[self racBind];
|
|
}
|
|
|
|
- (void)createUI {
|
|
[self.view addSubview:self.titleLabel];
|
|
[self.view addSubview:self.phoneInputView];
|
|
[self.view addSubview:self.codeInputView];
|
|
[self.view addSubview:self.pwdInputView];
|
|
[self.view addSubview:self.sureBtn];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(kStatusBarHeight);
|
|
make.height.mas_equalTo(44);
|
|
}];
|
|
[self.phoneInputView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(38);
|
|
make.right.mas_equalTo(-38);
|
|
make.top.mas_equalTo(139.0/812.0*KScreenHeight);
|
|
make.height.mas_equalTo(66);
|
|
}];
|
|
[self.codeInputView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.phoneInputView);
|
|
make.right.mas_equalTo(self.phoneInputView);
|
|
make.top.mas_equalTo(self.phoneInputView.mas_bottom).offset(16);
|
|
make.height.mas_equalTo(self.phoneInputView);
|
|
}];
|
|
[self.pwdInputView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.phoneInputView);
|
|
make.right.mas_equalTo(self.phoneInputView);
|
|
make.top.mas_equalTo(self.codeInputView.mas_bottom).offset(16);
|
|
make.height.mas_equalTo(self.phoneInputView);
|
|
}];
|
|
[self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.pwdInputView.mas_bottom).offset(51);
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.width.height.mas_equalTo(96);
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)racBind {
|
|
RAC(self.sureBtn, enabled) = [[RACSignal combineLatest:@[self.phoneInputView.inputTextField.rac_textSignal, self.pwdInputView.inputTextField.rac_textSignal, self.pwdInputView.inputTextField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* smsCode, NSString *password){
|
|
return @((phone.length > 0) && smsCode.length >= 5 && (password.length >= 6 && password.length <= 16));
|
|
}] takeUntil:self.rac_willDeallocSignal];
|
|
}
|
|
|
|
/// 确认
|
|
- (void)sureBtnClicked {
|
|
NSString *phone = self.phoneInputView.inputTextField.text;
|
|
NSString *smsCode = self.codeInputView.inputTextField.text;
|
|
NSString *password = self.pwdInputView.inputTextField.text;
|
|
[self.presenter resetPassword:phone newPwd:password smsCode:smsCode phoneAreaCode:@""];
|
|
}
|
|
|
|
#pragma mark - XPLoginInputViewDelegate
|
|
|
|
- (void)smsCodeAction {
|
|
NSString *phone = self.phoneInputView.inputTextField.text;
|
|
if (phone.length <= 0) {
|
|
[self showErrorToast:YMLocalizedString(@"XPForgetPwdViewController0")];
|
|
return;
|
|
}
|
|
[self.presenter phoneSmsCode:phone type:GetSmsType_Reset_Password phoneAreaCode:self.phoneAreaCode];
|
|
|
|
}
|
|
|
|
- (void)areaListAction {
|
|
XPLoginAraeViewController *codeVC = [XPLoginAraeViewController new];
|
|
codeVC.delegate = self;
|
|
[self.navigationController pushViewController:codeVC animated:YES];
|
|
}
|
|
|
|
- (void)chooseAreaCodeSuccess:(NSString *)code {
|
|
if (code.length > 0) {
|
|
self.phoneAreaCode = code;
|
|
[self.phoneInputView.areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@", code] forState:UIControlStateNormal];
|
|
}
|
|
}
|
|
|
|
#pragma mark - LoginForgetPasswordProtocol
|
|
|
|
///请求手机号的验证码成功
|
|
- (void)phoneSmsCodeSuccess {
|
|
[self showSuccessToast:YMLocalizedString(@"XPForgetPwdViewController1")];
|
|
[self.codeInputView fireTimer];
|
|
}
|
|
|
|
///重置密码成功
|
|
- (void)resetPasswrodSuccess {
|
|
[self showSuccessToast:YMLocalizedString(@"XPForgetPwdViewController2")];
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
}
|
|
|
|
#pragma mark - 懒加载
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.text = YMLocalizedString(@"XPForgetPwdViewController3");
|
|
_titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
|
|
_titleLabel.textColor = UIColor.whiteColor;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (XPLoginInputView *)phoneInputView {
|
|
if (!_phoneInputView) {
|
|
_phoneInputView = [[XPLoginInputView alloc] init];
|
|
_phoneInputView.areaStackView.hidden = NO;
|
|
_phoneInputView.delegate = self;
|
|
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPForgetPwdViewController4")];
|
|
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColor.whiteColor range:NSMakeRange(0, placeholder.length)];
|
|
_phoneInputView.inputTextField.attributedPlaceholder = placeholder;
|
|
_phoneInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
}
|
|
return _phoneInputView;
|
|
}
|
|
|
|
- (XPLoginInputView *)codeInputView {
|
|
if (!_codeInputView) {
|
|
_codeInputView = [[XPLoginInputView alloc] init];
|
|
_codeInputView.smsCodeBtn.hidden = NO;
|
|
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPForgetPwdViewController5")];
|
|
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColor.whiteColor range:NSMakeRange(0, placeholder.length)];
|
|
_codeInputView.inputTextField.attributedPlaceholder = placeholder;
|
|
_codeInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_codeInputView.delegate = self;
|
|
}
|
|
return _codeInputView;
|
|
}
|
|
|
|
- (XPLoginInputView *)pwdInputView {
|
|
if (!_pwdInputView) {
|
|
_pwdInputView = [[XPLoginInputView alloc] init];
|
|
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPForgetPwdViewController6")];
|
|
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColor.whiteColor range:NSMakeRange(0, placeholder.length)];
|
|
_pwdInputView.inputTextField.attributedPlaceholder = placeholder;
|
|
_pwdInputView.inputTextField.keyboardType = UIKeyboardTypeAlphabet;
|
|
_pwdInputView.inputTextField.secureTextEntry = YES;
|
|
}
|
|
return _pwdInputView;
|
|
}
|
|
|
|
- (UIButton *)sureBtn {
|
|
if (!_sureBtn) {
|
|
_sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_sureBtn setImage:[UIImage imageNamed:@"login_next"] forState:UIControlStateNormal];
|
|
[_sureBtn setImage:[UIImage imageNamed:@"login_next_disable"] forState:UIControlStateSelected];
|
|
[_sureBtn addTarget:self action:@selector(sureBtnClicked) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _sureBtn;
|
|
}
|
|
|
|
@end
|