123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // ModifyViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/22.
- //
- #import "ModifyViewController.h"
- #import "ModifyBodyView.h"
- #import "VeriCheckView.h"
- #import "LoginViewController.h"
- #import "AppDelegate.h"
- #import "CustomNavViewController.h"
- #import "JPUSHService.h"
- #import "UserInfoManager.h"
- @interface ModifyViewController ()
- {
- NSTimer *_time;
- int _count;
- }
- @property (nonatomic, strong) ModifyBodyView *bodyView;
- @end
- @implementation ModifyViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"修改密码"];
- [self configUI];
- }
- - (void)configUI {
- _bodyView = [ModifyBodyView shareInstance];
- [self.scrollView addSubview:_bodyView];
- [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.right.left.mas_equalTo(self.view);
- make.height.mas_equalTo(kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
- }];
-
- MJWeakSelf;
- [_bodyView modifyCallback:^(MODIFYACTION action, NSDictionary * _Nonnull parm) {
- [weakSelf operationWithAction:action parm:parm];
- }];
- self.bodyView.pwdField.tintColor = CLIENT_THEMECOLOR;
- self.bodyView.codeField.tintColor = CLIENT_THEMECOLOR;
- [self.bodyView.sureButton setBackgroundColor:CLIENT_THEMECOLOR];
- [self.bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
- }
- - (void)operationWithAction:(MODIFYACTION)action parm:(NSDictionary *)parm {
- if (action == MODIFYACTION_CODE) {
- // 图形化验证
- [self veriCheckWithParm:parm];
- }
- else if (action == MODIFYACTION_SURE) {
- [self modifyPassword:parm];
- }
- }
- #pragma mark -- 修改密码
- - (void)modifyPassword:(NSDictionary *)parm {
- [LOADING_MANAGER showCustomLoading:@"加载中..."];
- [KSNetworkingManager updatePasswordRequest:KS_POST authCode:[parm ks_stringValueForKey:@"code"] mobile:[parm ks_stringValueForKey:@"phone"] newPassword:[parm ks_stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeCustomLoading];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [LOADING_MANAGER KSShowMsg:@"修改成功" promptCompletion:^{
- [self toLoginView];
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeCustomLoading];
- }];
- }
- // 重新登录
- - (void)toLoginView {
- [APPLOGIN_MANAGER logoutActionWithMsg:@""];
- }
- #pragma mark --- 验证码
- - (void)veriCheckWithParm:(NSDictionary *)parm {
- NSString *phoneNo = [parm ks_stringValueForKey:@"phone"];
- // 图形化验证
- VeriCheckView *view = [VeriCheckView shareInstanceShowInView:self.view];
- __weak typeof(view) weakView = view;
- [view showViewCallback:^(NSDictionary * _Nonnull parm) {
- [self veriImageCodeWithParm:parm checkView:weakView];
- }];
- [view disPlayImageWithPhone:phoneNo];
- }
- // 发送短信 校验图形验证码
- - (void)veriImageCodeWithParm:(NSDictionary *)parm checkView:(VeriCheckView *)checkView {
- [LOADING_MANAGER showCustomLoading:@"加载中..."];
- [KSNetworkingManager sendSmsRequest:KS_POST mobile:[parm ks_stringValueForKey:@"phone"] type:@"PASSWD" code:[parm ks_stringValueForKey:@"code"] success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeCustomLoading];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [checkView hiddView];
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"验证码已发送"];
- [self codeButtonCountDown];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeCustomLoading];
- }];
- }
- - (void)codeButtonCountDown {
- _bodyView.codeButton.userInteractionEnabled = NO;
- [_bodyView.codeButton setTitleColor:HexRGB(0xe5e5e5) forState:UIControlStateNormal];
- __weak typeof(self) weakSelf = self;
- _time = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(buttonChangeAction) userInfo:nil repeats:YES];
- _count = 59;
- }
- - (void)clearButtonState {
- [_time invalidate];
- _time = nil;
- _count = 0;
- [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
- [_bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
- _bodyView.codeButton.userInteractionEnabled = YES;
- }
- #pragma mark ---- 验证码按钮状态
- - (void)buttonChangeAction {
- _bodyView.codeButton.userInteractionEnabled = NO;
- NSString *title = [NSString stringWithFormat:@"%ds",_count];
- [_bodyView.codeButton setTitle:title forState:UIControlStateNormal];
- _count--;
- if(_count == -1){
- [_time invalidate];
- _time = nil;
- [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
- [_bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
- _bodyView.codeButton.userInteractionEnabled = YES;
- }
- }
- - (void)dealloc {
- [_time invalidate];
- _time = nil;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|