ForgetPasswordViewController.mm 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // ForgetPasswordViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/10/17.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "ForgetPasswordViewController.h"
  9. #import "ForgetPasswordView.h"
  10. #import "UserAccountModel.h"
  11. #import "NSString+Extention.h"
  12. @interface ForgetPasswordViewController ()<UserAccountModelDelegate>
  13. {
  14. ForgetPasswordView *forgetPwdView; //忘记密码视图
  15. UserAccountModel *accountModel; //账号相关功能接口管理器
  16. }
  17. @property (nonatomic, strong)NSTimer *myTimer; //验证计时器
  18. @property (nonatomic, assign)NSInteger continueTime; //倒计时
  19. @property (nonatomic, assign) BOOL isReceivingCode; //是否正在接收验证码
  20. @end
  21. @implementation ForgetPasswordViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. //忘记密码界面视图初始化
  25. forgetPwdView = [[ForgetPasswordView alloc] init];
  26. self.view = forgetPwdView;
  27. __weak typeof(self) weakSelf = self;
  28. //获取验证码事件处理
  29. forgetPwdView.getCodeBtnClicked = ^(NSString * _Nonnull userPhone) {
  30. [weakSelf getCodeWithUserPhone:userPhone];
  31. };
  32. //检查验证码的合法性事件处理
  33. forgetPwdView.checkCodeBtnClicked = ^(NSString * _Nonnull userPhone, NSString * _Nonnull codeStr) {
  34. [weakSelf checkCodeWithUserPhone:userPhone codeStr:codeStr];
  35. };
  36. //重置密码事件处理
  37. forgetPwdView.resettingPwdBtnClicked = ^(NSString * _Nonnull userPhone, NSString * _Nonnull newPassword) {
  38. [weakSelf resetPasswordWithUserPhone:userPhone newPassword:newPassword];
  39. };
  40. //账号相关功能接口管理器
  41. accountModel = [[UserAccountModel alloc] init];
  42. accountModel.delegate = self;
  43. //设置导航栏
  44. [self setNaviStyle];
  45. }
  46. - (void)setNaviStyle {
  47. self.navigationItem.title = TS("Forget_Pwd");
  48. UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"new_back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(popViewController)];
  49. self.navigationItem.leftBarButtonItem = leftBtn;
  50. }
  51. #pragma mark - button event 按钮点击事件
  52. -(void)popViewController
  53. {
  54. if([SVProgressHUD isVisible]){
  55. [SVProgressHUD dismiss];
  56. }
  57. [self.navigationController popViewControllerAnimated:YES];
  58. }
  59. #pragma mark 获取验证码
  60. -(void)getCodeWithUserPhone:(NSString *)userPhone
  61. {
  62. //是否正在接收验证码
  63. if (self.isReceivingCode == NO) {
  64. if (userPhone.length == 0 ) {
  65. [SVProgressHUD showErrorWithStatus:TS("moblie_error")];
  66. return;
  67. }
  68. //判断用户输入的邮箱还是手机号
  69. if([userPhone containsString:@"@"]){
  70. //邮箱
  71. //邮箱注册
  72. if (![NSString isValidateEmail:userPhone])//邮箱格式判断是否正确
  73. {
  74. [SVProgressHUD showErrorWithStatus:TS("error_email_formatter")];
  75. return;
  76. }
  77. }else{
  78. //手机号
  79. //手机号码长度及格式
  80. if ([userPhone hasPrefix:@"0"]||userPhone.length != 11) {
  81. [SVProgressHUD showErrorWithStatus:TS("Number_Format_Error")];
  82. return;
  83. }
  84. }
  85. [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
  86. //获取验证码
  87. [accountModel fogetPwdWithPhoneNum:userPhone];
  88. self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(myTimeCount) userInfo:nil repeats:YES];
  89. self.continueTime = 120;
  90. self.isReceivingCode = YES;
  91. }
  92. }
  93. #pragma mark 检查验证码的合法性
  94. -(void)checkCodeWithUserPhone:(NSString *)userPhone codeStr:(NSString *)codeStr
  95. {
  96. //判断手机码哦或者邮箱是否为空
  97. if (forgetPwdView.userPhone.text.length == 0 ) {
  98. [SVProgressHUD showErrorWithStatus:TS("Empty_Phone_Number")];
  99. return;
  100. }
  101. //验证码栏不能为空
  102. if (forgetPwdView.inputCode.text.length == 0)
  103. {
  104. [SVProgressHUD showErrorWithStatus:TS("input_code")];
  105. return;
  106. }
  107. [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
  108. //校验验证码
  109. [accountModel checkCode:userPhone code:codeStr];
  110. }
  111. #pragma mark 重置密码
  112. -(void)resetPasswordWithUserPhone:(NSString *)userPhone newPassword:(NSString *)newPassword
  113. {
  114. //密码字符格式
  115. BOOL isMatch = [NSString isValidatePassword:newPassword];
  116. //判断密码长度
  117. if(!isMatch||(newPassword.length < 8||newPassword.length > 32))
  118. {
  119. [SVProgressHUD showErrorWithStatus:TS("edit_pwd_error5")];
  120. return;
  121. }
  122. [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
  123. //重置密码
  124. [accountModel resetPassword:userPhone newPassword:newPassword];
  125. }
  126. //倒计时处理,刷新时间
  127. -(void)myTimeCount
  128. {
  129. NSString *myTitle = [NSString stringWithFormat:@"%ld",(long)self.continueTime];
  130. [forgetPwdView.getCode setTitle:[myTitle stringByAppendingString:TS("resend_Again")] forState:UIControlStateNormal];
  131. self.continueTime = self.continueTime - 1;
  132. if (self.continueTime <= 0) {
  133. [self getCodeBtnResign];
  134. }
  135. }
  136. //重置计时器
  137. -(void)getCodeBtnResign
  138. {
  139. if (self.myTimer) {
  140. [self.myTimer invalidate];
  141. self.myTimer = nil;
  142. }
  143. [forgetPwdView.getCode setTitle:TS("get_code") forState:UIControlStateNormal];
  144. self.isReceivingCode = NO;
  145. }
  146. #pragma mark - funsdk 回调处理
  147. //获取验证码回调
  148. -(void)forgetPwdGetCodeDelegateResult:(long)reslut userName:(NSString *)name
  149. {
  150. [SVProgressHUD dismiss];
  151. if (reslut >= 0) {
  152. forgetPwdView.userNameLabel.text = [NSString stringWithFormat:@"%@%@",TS("forget_username_is"),name];
  153. }
  154. else{
  155. [MessageUI ShowErrorInt:(int)reslut];
  156. [self getCodeBtnResign];
  157. }
  158. }
  159. //检查验证码的合法性回调
  160. -(void)checkCodeDelegateResult:(long)reslut
  161. {
  162. [SVProgressHUD dismiss];
  163. if (reslut >= 0) {
  164. forgetPwdView.checkBtn.hidden = YES;
  165. forgetPwdView.confirmPwdView.hidden = NO;
  166. }
  167. else{
  168. [MessageUI ShowErrorInt:(int)reslut];
  169. }
  170. }
  171. //重置密码回调
  172. -(void)resetPasswordDelegateResult:(long)reslut
  173. {
  174. [SVProgressHUD dismiss];
  175. if (reslut >= 0) {
  176. [SVProgressHUD showSuccessWithStatus:TS("Success")];
  177. }
  178. else{
  179. [MessageUI ShowErrorInt:(int)reslut];
  180. }
  181. }
  182. @end