239 lines
9.0 KiB
Objective-C
239 lines
9.0 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 "CountDownHelper.h"
|
|
|
|
#import "UIImage+Utils.h"
|
|
///Presenter
|
|
#import "LoginForgetPasswordPresent.h"
|
|
#import "LoginForgetPasswordProtocol.h"
|
|
///View
|
|
#import "LoginForgetEditView.h"
|
|
#import "XPLoginAraeViewController.h"
|
|
|
|
|
|
@interface LoginForgetPasswordViewController ()<XPLoginAraeViewControllerDelegate,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
|
|
|
|
- (void)dealloc {
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
}
|
|
|
|
- (LoginForgetPasswordPresent *)createPresenter {
|
|
return [[LoginForgetPasswordPresent alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
NSString *code = [NSString getCountryCode];
|
|
self.pi_phoneAreaCode = [code stringByReplacingOccurrencesOfString:@"+" withString:@""];
|
|
[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 = YMLocalizedString(@"LoginForgetPasswordViewController0");
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
|
[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.top.mas_equalTo(self.view).mas_offset(kGetScaleWidth(30));
|
|
make.leading.trailing.equalTo(self.view).inset(kGetScaleWidth(15));
|
|
}];
|
|
|
|
[self.finishButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.mas_equalTo(self.view).inset(kGetScaleWidth(15));
|
|
make.height.mas_equalTo(45);
|
|
make.top.mas_equalTo(self.stackView.mas_bottom).offset(kGetScaleWidth(51));
|
|
}];
|
|
|
|
[self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(kGetScaleWidth(48));
|
|
}];
|
|
|
|
[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 > 0 && code.length > 0 && password.length >= 6 && password.length <= 16);
|
|
}];
|
|
}
|
|
#pragma mark - XPChooseAreaCodeVCDelegate
|
|
-(void)chooseAreaCodeSuccess:(NSString *)code{
|
|
self.pi_phoneAreaCode = code;
|
|
self.phoneView.areaCode = [NSString stringWithFormat:@"+%@",code];
|
|
}
|
|
#pragma mark - LoginForgetPasswordProtocol
|
|
///请求手机号的验证码成功
|
|
- (void)phoneSmsCodeSuccess {
|
|
[self hideHUD];
|
|
self.codeView.authCodeButton.enabled= NO;
|
|
[self showSuccessToast:YMLocalizedString(@"LoginForgetPasswordViewController1")];
|
|
[[CountDownHelper shareHelper] openCountdownWithTime:60];
|
|
}
|
|
///重置密码成功
|
|
- (void)resetPasswrodSuccess {
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
[self showSuccessToast:YMLocalizedString(@"LoginForgetPasswordViewController2")];
|
|
if(self.isLogout == YES){
|
|
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC));
|
|
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
|
|
[self.presenter logout];
|
|
});
|
|
|
|
}else{
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
}
|
|
#pragma mark - CountDownHelperDelegate
|
|
///倒计时进行中
|
|
- (void)onCountdownOpen:(int)time {
|
|
[self.codeView.authCodeButton setTitle:[NSString stringWithFormat:YMLocalizedString(@"LoginForgetPasswordViewController3"), time] forState:UIControlStateDisabled];
|
|
}
|
|
///倒计时结束
|
|
- (void)onCountdownFinish {
|
|
self.codeView.authCodeButton.enabled= YES;
|
|
[self.codeView.authCodeButton setTitle:YMLocalizedString(@"LoginForgetPasswordViewController4") forState:UIControlStateNormal];
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)finishButtonAction:(UIButton *)sender {
|
|
[self.view endEditing:YES];
|
|
[self.presenter resetPassword:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,self.phoneView.textField.text] newPwd:self.passwordView.textField.text smsCode:self.codeView.textField.text phoneAreaCode:self.pi_phoneAreaCode];
|
|
}
|
|
|
|
- (void)authCodeButtonAction:(UIButton *)sender {
|
|
if(self.phoneView.textField.text.length == 0){
|
|
[self showErrorToast:YMLocalizedString(@"LoginForgetPasswordViewController7")];
|
|
return;
|
|
}
|
|
[self.view endEditing:YES];
|
|
[self showLoading];
|
|
[self.presenter phoneSmsCode:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,self.phoneView.textField.text] type:GetSmsType_Reset_Password phoneAreaCode:self.pi_phoneAreaCode];
|
|
|
|
}
|
|
-(void)chooseAreaCodeAction{
|
|
XPLoginAraeViewController *codeVC = [XPLoginAraeViewController new];
|
|
codeVC.delegate = self;
|
|
[self.navigationController pushViewController:codeVC animated:YES];
|
|
}
|
|
-(void)hidePasswordAction{
|
|
self.passwordView.rightButton.selected = !self.passwordView.rightButton.selected;
|
|
self.passwordView.textField.secureTextEntry = !self.passwordView.rightButton.selected;
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (UIButton *)finishButton{
|
|
if (!_finishButton) {
|
|
_finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
_finishButton.layer.masksToBounds = YES;
|
|
_finishButton.layer.cornerRadius = kGetScaleWidth(24);
|
|
[_finishButton setTitle:YMLocalizedString(@"LoginForgetPasswordViewController6") forState:UIControlStateNormal];
|
|
_finishButton.titleLabel.font = kFontRegular(16);
|
|
[_finishButton setTitleColor:[DJDKMIMOMColor confirmButtonTextColor] forState:UIControlStateNormal];
|
|
_finishButton.enabled = NO;
|
|
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(345), kGetScaleWidth(46))];
|
|
[_finishButton setBackgroundImage:image forState:UIControlStateNormal];
|
|
[_finishButton addTarget:self action:@selector(finishButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _finishButton;
|
|
}
|
|
|
|
|
|
- (UIStackView *)stackView {
|
|
if (!_stackView) {
|
|
_stackView = [[UIStackView alloc] init];
|
|
_stackView.axis = UILayoutConstraintAxisVertical;
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
_stackView.spacing = kGetScaleWidth(25);
|
|
}
|
|
return _stackView;
|
|
}
|
|
|
|
- (LoginForgetEditView *)phoneView {
|
|
if (!_phoneView) {
|
|
_phoneView = [[LoginForgetEditView alloc] init];
|
|
// _phoneView.placeholder = YMLocalizedString(@"LoginForgetPasswordViewController7");
|
|
_phoneView.textField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_phoneView.type = LoginForgetEditViewTypeNormal;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(chooseAreaCodeAction)];
|
|
[_phoneView.codeView addGestureRecognizer:tap];
|
|
}
|
|
return _phoneView;
|
|
}
|
|
|
|
- (LoginForgetEditView *)codeView {
|
|
if (!_codeView) {
|
|
_codeView = [[LoginForgetEditView alloc] init];
|
|
_codeView.placeholder = YMLocalizedString(@"LoginForgetPasswordViewController8");
|
|
_codeView.type = LoginForgetEditViewTypeSms;
|
|
_codeView.textField.keyboardType = UIKeyboardTypeNumberPad;
|
|
[_codeView.authCodeButton addTarget:self action:@selector(authCodeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _codeView;
|
|
}
|
|
|
|
- (LoginForgetEditView *)passwordView {
|
|
if (!_passwordView) {
|
|
_passwordView = [[LoginForgetEditView alloc] init];
|
|
_passwordView.textField.secureTextEntry = YES;
|
|
_passwordView.placeholder = YMLocalizedString(@"LoginForgetPasswordViewController9");
|
|
_passwordView.type = LoginForgetEditViewTypePassword;
|
|
_passwordView.textField.keyboardType = UIKeyboardTypeASCIICapable;
|
|
_passwordView.textField.clearButtonMode = UITextFieldViewModeAlways;
|
|
[_passwordView.rightButton addTarget:self action:@selector(hidePasswordAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _passwordView;
|
|
}
|
|
|
|
@end
|