ModifyViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // ModifyViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/22.
  6. //
  7. #import "ModifyViewController.h"
  8. #import "ModifyBodyView.h"
  9. #import "VeriCheckView.h"
  10. #import "LoginViewController.h"
  11. #import "AppDelegate.h"
  12. #import "CustomNavViewController.h"
  13. #import "JPUSHService.h"
  14. #import "UserInfoManager.h"
  15. @interface ModifyViewController ()
  16. {
  17. NSTimer *_time;
  18. int _count;
  19. }
  20. @property (nonatomic, strong) ModifyBodyView *bodyView;
  21. @end
  22. @implementation ModifyViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self allocTitle:@"修改密码"];
  27. [self configUI];
  28. }
  29. - (void)configUI {
  30. _bodyView = [ModifyBodyView shareInstance];
  31. [self.scrollView addSubview:_bodyView];
  32. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.mas_equalTo(self.scrollView.mas_top);
  34. make.right.left.mas_equalTo(self.view);
  35. make.height.mas_equalTo(kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
  36. }];
  37. MJWeakSelf;
  38. [_bodyView modifyCallback:^(MODIFYACTION action, NSDictionary * _Nonnull parm) {
  39. [weakSelf operationWithAction:action parm:parm];
  40. }];
  41. self.bodyView.pwdField.tintColor = CLIENT_THEMECOLOR;
  42. self.bodyView.codeField.tintColor = CLIENT_THEMECOLOR;
  43. [self.bodyView.sureButton setBackgroundColor:CLIENT_THEMECOLOR];
  44. [self.bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
  45. }
  46. - (void)operationWithAction:(MODIFYACTION)action parm:(NSDictionary *)parm {
  47. if (action == MODIFYACTION_CODE) {
  48. // 图形化验证
  49. [self veriCheckWithParm:parm];
  50. }
  51. else if (action == MODIFYACTION_SURE) {
  52. [self modifyPassword:parm];
  53. }
  54. }
  55. #pragma mark -- 修改密码
  56. - (void)modifyPassword:(NSDictionary *)parm {
  57. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  58. [KSNetworkingManager updatePasswordRequest:KS_POST authCode:[parm ks_stringValueForKey:@"code"] mobile:[parm ks_stringValueForKey:@"phone"] newPassword:[parm ks_stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) {
  59. [LOADING_MANAGER removeCustomLoading];
  60. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  61. [LOADING_MANAGER KSShowMsg:@"修改成功" promptCompletion:^{
  62. [self toLoginView];
  63. }];
  64. }
  65. else {
  66. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  67. }
  68. } faliure:^(NSError * _Nonnull error) {
  69. [LOADING_MANAGER removeCustomLoading];
  70. }];
  71. }
  72. // 重新登录
  73. - (void)toLoginView {
  74. [APPLOGIN_MANAGER logoutActionWithMsg:@""];
  75. }
  76. #pragma mark --- 验证码
  77. - (void)veriCheckWithParm:(NSDictionary *)parm {
  78. NSString *phoneNo = [parm ks_stringValueForKey:@"phone"];
  79. // 图形化验证
  80. VeriCheckView *view = [VeriCheckView shareInstanceShowInView:self.view];
  81. __weak typeof(view) weakView = view;
  82. [view showViewCallback:^(NSDictionary * _Nonnull parm) {
  83. [self veriImageCodeWithParm:parm checkView:weakView];
  84. }];
  85. [view disPlayImageWithPhone:phoneNo];
  86. }
  87. // 发送短信 校验图形验证码
  88. - (void)veriImageCodeWithParm:(NSDictionary *)parm checkView:(VeriCheckView *)checkView {
  89. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  90. [KSNetworkingManager sendSmsRequest:KS_POST mobile:[parm ks_stringValueForKey:@"phone"] type:@"PASSWD" code:[parm ks_stringValueForKey:@"code"] success:^(NSDictionary * _Nonnull dic) {
  91. [LOADING_MANAGER removeCustomLoading];
  92. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  93. [checkView hiddView];
  94. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"验证码已发送"];
  95. [self codeButtonCountDown];
  96. }
  97. else {
  98. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  99. }
  100. } faliure:^(NSError * _Nonnull error) {
  101. [LOADING_MANAGER removeCustomLoading];
  102. }];
  103. }
  104. - (void)codeButtonCountDown {
  105. _bodyView.codeButton.userInteractionEnabled = NO;
  106. [_bodyView.codeButton setTitleColor:HexRGB(0xe5e5e5) forState:UIControlStateNormal];
  107. __weak typeof(self) weakSelf = self;
  108. _time = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(buttonChangeAction) userInfo:nil repeats:YES];
  109. _count = 59;
  110. }
  111. - (void)clearButtonState {
  112. [_time invalidate];
  113. _time = nil;
  114. _count = 0;
  115. [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  116. [_bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
  117. _bodyView.codeButton.userInteractionEnabled = YES;
  118. }
  119. #pragma mark ---- 验证码按钮状态
  120. - (void)buttonChangeAction {
  121. _bodyView.codeButton.userInteractionEnabled = NO;
  122. NSString *title = [NSString stringWithFormat:@"%ds",_count];
  123. [_bodyView.codeButton setTitle:title forState:UIControlStateNormal];
  124. _count--;
  125. if(_count == -1){
  126. [_time invalidate];
  127. _time = nil;
  128. [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  129. [_bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
  130. _bodyView.codeButton.userInteractionEnabled = YES;
  131. }
  132. }
  133. - (void)dealloc {
  134. [_time invalidate];
  135. _time = nil;
  136. }
  137. /*
  138. #pragma mark - Navigation
  139. // In a storyboard-based application, you will often want to do a little preparation before navigation
  140. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  141. // Get the new view controller using [segue destinationViewController].
  142. // Pass the selected object to the new view controller.
  143. }
  144. */
  145. @end