202 lines
6.7 KiB
Objective-C
202 lines
6.7 KiB
Objective-C
//
|
||
// LoginForgetPasswordViewController.m
|
||
// xplan-ios
|
||
//
|
||
// Created by 冯硕 on 2021/9/10.
|
||
//
|
||
|
||
#import "LoginForgetPasswordViewController.h"
|
||
///第三方
|
||
#import <Masonry/Masonry.h>
|
||
#import <ReactiveObjC/ReactiveObjC.h>
|
||
///Tool
|
||
#import "ThemeColor.h"
|
||
#import "CountDownHelper.h"
|
||
#import "UIImage+Utils.h"
|
||
///Presenter
|
||
#import "LoginForgetPasswordPresent.h"
|
||
#import "LoginForgetPasswordProtocol.h"
|
||
///View
|
||
#import "LoginForgetEditView.h"
|
||
|
||
|
||
@interface LoginForgetPasswordViewController ()<LoginForgetPasswordProtocol, CountDownHelperDelegate>
|
||
///容器
|
||
@property (nonatomic,strong) UIStackView *stackView;
|
||
///手机号
|
||
@property (nonatomic,strong) LoginForgetEditView *phoneView;
|
||
///验证码
|
||
@property (nonatomic,strong) LoginForgetEditView *codeView;
|
||
///密码
|
||
@property (nonatomic,strong) LoginForgetEditView *passwordView;
|
||
///完成
|
||
@property (nonatomic,strong) UIButton *finishButton;
|
||
|
||
@end
|
||
|
||
@implementation LoginForgetPasswordViewController
|
||
|
||
- (LoginForgetPasswordPresent *)createPresenter {
|
||
return [[LoginForgetPasswordPresent alloc] init];
|
||
}
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
[self initSubViews];
|
||
[self initSubViewConstraints];
|
||
[self initEvents];
|
||
}
|
||
|
||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||
[self.view endEditing:NO];
|
||
}
|
||
|
||
- (void)viewDidDisappear:(BOOL)animated {
|
||
[super viewDidDisappear:animated];
|
||
[[CountDownHelper shareHelper] stopCountDown];
|
||
}
|
||
|
||
#pragma mark - Private Method
|
||
- (void)initSubViews {
|
||
self.title = @"忘记密码";
|
||
[CountDownHelper shareHelper].delegate = self;
|
||
[self.view addSubview:self.stackView];
|
||
[self.view addSubview:self.finishButton];
|
||
|
||
[self.stackView addArrangedSubview:self.phoneView];
|
||
[self.stackView addArrangedSubview:self.codeView];
|
||
[self.stackView addArrangedSubview:self.passwordView];
|
||
}
|
||
|
||
- (void)initSubViewConstraints {
|
||
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.right.top.mas_equalTo(self.view);
|
||
}];
|
||
|
||
[self.finishButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.right.mas_equalTo(self.view).inset(52);
|
||
make.height.mas_equalTo(45);
|
||
make.top.mas_equalTo(self.stackView.mas_bottom).offset(20);
|
||
}];
|
||
|
||
[self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.height.mas_equalTo(45);
|
||
}];
|
||
|
||
[self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.height.mas_equalTo(self.phoneView);
|
||
}];
|
||
|
||
[self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.height.mas_equalTo(self.phoneView);
|
||
}];
|
||
}
|
||
|
||
- (void)initEvents {
|
||
@weakify(self);
|
||
RAC(self.finishButton, enabled) = [RACSignal combineLatest:@[self.phoneView.textField.rac_textSignal, self.codeView.textField.rac_textSignal, self.passwordView.textField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString *code, NSString *password){
|
||
return @(phone.length == 11 && code.length > 0 && password.length >= 6 && password.length <= 16);
|
||
}];
|
||
|
||
///点击了发送验证码
|
||
[[self.codeView.authCodeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
|
||
@strongify(self);
|
||
if (self.phoneView.textField.text.length != 11) {
|
||
[self showErrorToast:@"请输入正确的手机号码"];
|
||
} else {
|
||
[self.presenter phoneSmsCode:self.phoneView.textField.text type:3];
|
||
}
|
||
}];
|
||
|
||
///点击了完成按钮
|
||
[[self.finishButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
|
||
@strongify(self);
|
||
[self.presenter resetPassword:self.phoneView.textField.text newPwd:self.passwordView.textField.text smsCode:self.codeView.textField.text];
|
||
}];
|
||
}
|
||
|
||
#pragma mark - LoginForgetPasswordProtocol
|
||
///请求手机号的验证码成功
|
||
- (void)phoneSmsCodeSuccess {
|
||
self.codeView.authCodeButton.enabled= NO;
|
||
[self showSuccessToast:@"验证码发送成功"];
|
||
[[CountDownHelper shareHelper] openCountdownWithTime:60];
|
||
}
|
||
///重置密码成功
|
||
- (void)resetPasswrodSuccess {
|
||
[[CountDownHelper shareHelper] stopCountDown];
|
||
[self showSuccessToast:@"重置密码成功"];
|
||
[self.navigationController popViewControllerAnimated:YES];
|
||
|
||
}
|
||
#pragma mark - CountDownHelperDelegate
|
||
///倒计时进行中
|
||
- (void)onCountdownOpen:(int)time {
|
||
[self.codeView.authCodeButton setTitle:[NSString stringWithFormat:@"%ds后重试", time] forState:UIControlStateDisabled];
|
||
}
|
||
///倒计时结束
|
||
- (void)onCountdownFinish {
|
||
self.codeView.authCodeButton.enabled= YES;
|
||
[self.codeView.authCodeButton setTitle:@"重新发送" forState:UIControlStateNormal];
|
||
}
|
||
#pragma mark - Getters And Setters
|
||
- (UIButton *)finishButton{
|
||
if (!_finishButton) {
|
||
_finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
_finishButton.layer.masksToBounds = YES;
|
||
_finishButton.layer.cornerRadius = 45/2.f;
|
||
[_finishButton setTitle:@"提交" forState:UIControlStateNormal];
|
||
_finishButton.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
|
||
[_finishButton setTitleColor:[ThemeColor confirmButtonTextColor] forState:UIControlStateNormal];
|
||
_finishButton.enabled = NO;
|
||
UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor], [ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
|
||
[_finishButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[ThemeColor disableButtonColor], [ThemeColor disableButtonColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateDisabled];
|
||
[_finishButton setBackgroundImage:image forState:UIControlStateNormal];
|
||
}
|
||
return _finishButton;
|
||
}
|
||
|
||
|
||
- (UIStackView *)stackView {
|
||
if (!_stackView) {
|
||
_stackView = [[UIStackView alloc] init];
|
||
_stackView.axis = UILayoutConstraintAxisVertical;
|
||
_stackView.distribution = UIStackViewDistributionFill;
|
||
_stackView.alignment = UIStackViewAlignmentFill;
|
||
_stackView.spacing = 0;
|
||
}
|
||
return _stackView;
|
||
}
|
||
|
||
- (LoginForgetEditView *)phoneView {
|
||
if (!_phoneView) {
|
||
_phoneView = [[LoginForgetEditView alloc] init];
|
||
_phoneView.placeholder = @"请输入手机号";
|
||
_phoneView.type = LoginForgetEditViewTypeNormal;
|
||
}
|
||
return _phoneView;
|
||
}
|
||
|
||
- (LoginForgetEditView *)codeView {
|
||
if (!_codeView) {
|
||
_codeView = [[LoginForgetEditView alloc] init];
|
||
_codeView.placeholder = @"请输入验证码";
|
||
_codeView.type = LoginForgetEditViewTypeSms;
|
||
}
|
||
return _codeView;
|
||
}
|
||
|
||
- (LoginForgetEditView *)passwordView {
|
||
if (!_passwordView) {
|
||
_passwordView = [[LoginForgetEditView alloc] init];
|
||
_passwordView.placeholder = @"请输入密码(6-16个字符)";
|
||
_passwordView.type = LoginForgetEditViewTypePassword;
|
||
_passwordView.textField.keyboardType = UIKeyboardTypeASCIICapable;
|
||
_passwordView.textField.secureTextEntry = YES;
|
||
_passwordView.textField.clearButtonMode = UITextFieldViewModeAlways;
|
||
}
|
||
return _passwordView;
|
||
}
|
||
|
||
@end
|