ModifyViewController.m 6.5 KB

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