ModifyViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "RCConnectionManager.h"
  15. #import "UserInfoManager.h"
  16. @interface ModifyViewController ()
  17. {
  18. NSTimer *_time;
  19. int _count;
  20. }
  21. @property (nonatomic, strong) ModifyBodyView *bodyView;
  22. @end
  23. @implementation ModifyViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. [self allocTitle:@"修改密码"];
  28. [self configUI];
  29. }
  30. - (void)configUI {
  31. _bodyView = [ModifyBodyView shareInstance];
  32. [self.scrollView addSubview:_bodyView];
  33. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.mas_equalTo(self.scrollView.mas_top);
  35. make.right.left.mas_equalTo(self.view);
  36. make.height.mas_equalTo(kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
  37. }];
  38. MJWeakSelf;
  39. [_bodyView modifyCallback:^(MODIFYACTION action, NSDictionary * _Nonnull parm) {
  40. [weakSelf operationWithAction:action parm:parm];
  41. }];
  42. }
  43. - (void)operationWithAction:(MODIFYACTION)action parm:(NSDictionary *)parm {
  44. if (action == MODIFYACTION_CODE) {
  45. // 图形化验证
  46. [self veriCheckWithParm:parm];
  47. }
  48. else if (action == MODIFYACTION_SURE) {
  49. [self modifyPassword:parm];
  50. }
  51. }
  52. #pragma mark -- 修改密码
  53. - (void)modifyPassword:(NSDictionary *)parm {
  54. [self showhud];
  55. [KSNetworkingManager updatePasswordRequest:KS_POST authCode:[parm ks_stringValueForKey:@"code"] mobile:[parm ks_stringValueForKey:@"phone"] newPassword:[parm ks_stringValueForKey:@"password"] success:^(NSDictionary * _Nonnull dic) {
  56. [self removehub];
  57. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  58. MJWeakSelf;
  59. [self KSShowMsg:@"修改成功" promptCompletion:^{
  60. [weakSelf toLoginView];
  61. }];
  62. }
  63. else {
  64. [self MBPShow:MESSAGEKEY];
  65. }
  66. } faliure:^(NSError * _Nonnull error) {
  67. [self removehub];
  68. }];
  69. }
  70. // 重新登录
  71. - (void)toLoginView {
  72. USER_MANAGER.hasShowFlash = NO;
  73. [RCConnectionManager shareManager].isNeedJoin = NO;
  74. [RCConnectionManager shareManager].isNeedShowMessage = NO;
  75. [[RCIM sharedRCIM] logout];
  76. [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
  77. // 取消推送别名
  78. [JPUSHService deleteAlias:nil seq:0];
  79. [[NSUserDefaults standardUserDefaults] removeObjectForKey:TokenKey];
  80. [[NSUserDefaults standardUserDefaults] removeObjectForKey:Token_type];
  81. [[NSUserDefaults standardUserDefaults] removeObjectForKey:RefreshToken];
  82. [[NSUserDefaults standardUserDefaults] removeObjectForKey:RongTokenKey];
  83. [[NSUserDefaults standardUserDefaults] synchronize];
  84. [KSNetworkingManager clearRequestHeader];
  85. LoginViewController *loginVC = [[LoginViewController alloc] init];
  86. CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:loginVC];
  87. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  88. appDelegate.window.rootViewController = navCtrl;
  89. }
  90. #pragma mark --- 验证码
  91. - (void)veriCheckWithParm:(NSDictionary *)parm {
  92. NSString *phoneNo = [parm ks_stringValueForKey:@"phone"];
  93. // 图形化验证
  94. VeriCheckView *view = [VeriCheckView shareInstanceShowInView:self.view];
  95. __weak typeof(view) weakView = view;
  96. [view showViewCallback:^(NSDictionary * _Nonnull parm) {
  97. [self veriImageCodeWithParm:parm checkView:weakView];
  98. }];
  99. [view disPlayImageWithPhone:phoneNo];
  100. }
  101. - (void)veriImageCodeWithParm:(NSDictionary *)parm checkView:(VeriCheckView *)checkView {
  102. [self showhud];
  103. [KSNetworkingManager verifyLoginImageRequest:KS_POST phone:[parm ks_stringValueForKey:@"phone"] code:[parm ks_stringValueForKey:@"code"] success:^(NSDictionary * _Nonnull dic) {
  104. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  105. [checkView hiddView];
  106. [self sendSMSRequestWithParm:parm];
  107. }
  108. else {
  109. [self removehub];
  110. [self MBShowInWindow:MESSAGEKEY];
  111. }
  112. } faliure:^(NSError * _Nonnull error) {
  113. [self removehub];
  114. }];
  115. }
  116. // 发送短信
  117. - (void)sendSMSRequestWithParm:(NSDictionary *)parm {
  118. [KSNetworkingManager sendSmsRequest:KS_POST mobile:[parm ks_stringValueForKey:@"phone"] type:@"PASSWD" success:^(NSDictionary * _Nonnull dic) {
  119. [self removehub];
  120. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  121. [self MBPShow:@"验证码已发送"];
  122. [self codeButtonCountDown];
  123. }
  124. else {
  125. [self MBPShow:MESSAGEKEY];
  126. }
  127. } faliure:^(NSError * _Nonnull error) {
  128. [self removehub];
  129. }];
  130. }
  131. - (void)codeButtonCountDown {
  132. _bodyView.codeButton.userInteractionEnabled = NO;
  133. [_bodyView.codeButton setTitleColor:HexRGB(0xe5e5e5) forState:UIControlStateNormal];
  134. __weak typeof(self) weakSelf = self;
  135. _time = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(buttonChangeAction) userInfo:nil repeats:YES];
  136. _count = 59;
  137. }
  138. - (void)clearButtonState {
  139. [_time invalidate];
  140. _time = nil;
  141. _count = 0;
  142. [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  143. [_bodyView.codeButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  144. _bodyView.codeButton.userInteractionEnabled = YES;
  145. }
  146. #pragma mark ---- 验证码按钮状态
  147. - (void)buttonChangeAction {
  148. _bodyView.codeButton.userInteractionEnabled = NO;
  149. NSString *title = [NSString stringWithFormat:@"%ds",_count];
  150. [_bodyView.codeButton setTitle:title forState:UIControlStateNormal];
  151. _count--;
  152. if(_count == -1){
  153. [_time invalidate];
  154. _time = nil;
  155. [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  156. [_bodyView.codeButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  157. _bodyView.codeButton.userInteractionEnabled = YES;
  158. }
  159. }
  160. - (void)dealloc {
  161. [_time invalidate];
  162. _time = nil;
  163. }
  164. /*
  165. #pragma mark - Navigation
  166. // In a storyboard-based application, you will often want to do a little preparation before navigation
  167. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  168. // Get the new view controller using [segue destinationViewController].
  169. // Pass the selected object to the new view controller.
  170. }
  171. */
  172. @end