UserRestPassword2ViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // UserRestPassword2ViewController.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/30.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XenonSDK.h"
  9. #import "RootViewController.h"
  10. #import "UserRestPassword2ViewController.h"
  11. #import "NSBundle+KODLocalizable.h"
  12. #import "KODCommonConst.h"
  13. @interface UserRestPassword2ViewController () <UITextFieldDelegate>
  14. @end
  15. @implementation UserRestPassword2ViewController
  16. - (void)setNewPasswordTextField:(id)sender {
  17. self.passwordTextField = sender;
  18. }
  19. - (void)sdk_dismissViewController:(id)sender {
  20. if (self.navigationController.viewControllers.count > 2) {
  21. // if viewControllers[1] is UserRestPasswordViewController {
  22. // navigationController?.popToViewController(viewControllers[0], animated: true)
  23. // return
  24. // }
  25. }
  26. return [super sdk_dismissViewController:sender];
  27. }
  28. - (void)displayModeForPassword:(UIButton*)sender {
  29. // Toggle password display mode.
  30. sender.selected = !sender.selected;
  31. if (self.passwordTextField.tag == sender.tag) {
  32. self.passwordTextField.secureTextEntry = sender.selected;
  33. }
  34. if (self.confirmPasswordTextField.tag == sender.tag) {
  35. self.confirmPasswordTextField.secureTextEntry = sender.selected;
  36. }
  37. }
  38. - (void)securityCodeForReset:(id)sender {
  39. [self.view endEditing:YES];
  40. NSString* phone = self.phone;
  41. NSString* code = self.code;
  42. NSString* newPassword = self.passwordTextField.text;
  43. NSString* confirmPassword = self.confirmPasswordTextField.text;
  44. if (newPassword.length == 0) {
  45. //请输入新的密码
  46. NSString *str1 = [NSBundle KOD_localizedStringForKey:PleaseInputNewPwd];
  47. [XSNetwork showHudFailure:str1];
  48. return;
  49. }
  50. if (confirmPassword.length == 0) {
  51. //请再次输入新的密码
  52. NSString *str1 = [NSBundle KOD_localizedStringForKey:PleaseAgainInputNewPwd];
  53. [XSNetwork showHudFailure:str1];
  54. return;
  55. }
  56. if (![newPassword isEqual:confirmPassword]) {
  57. //两次输入的密码不一致
  58. NSString *str1 = [NSBundle KOD_localizedStringForKey:SecondInputPwdDiff];
  59. [XSNetwork showHudFailure:str1];
  60. return;
  61. }
  62. [XSNetwork showHudLoading];
  63. [XSNetwork resetWithPhone:phone code:code password:newPassword complete:^(id object, NSError *error) {
  64. if (error != nil) {
  65. [XSNetwork showHudFailure:error];
  66. return;
  67. }
  68. //密码修改成功
  69. NSString *str1 = [NSBundle KOD_localizedStringForKey:PwdChangeSuccess];
  70. [XSNetwork showHudSuccess:str1];
  71. if (self.navigationController.viewControllers.count <= 2) {
  72. [self.navigationController popViewControllerAnimated:YES];
  73. return ;
  74. }
  75. UIViewController* pop = self.navigationController.viewControllers[self.navigationController.viewControllers.count - 2 - 1];
  76. [self.navigationController popToViewController:pop animated:YES];
  77. }];
  78. }
  79. - (BOOL)textFieldShouldReturn:(UITextField*)textField {
  80. if (textField.returnKeyType == UIReturnKeyDone) {
  81. return NO;
  82. }
  83. if (textField == self.passwordTextField) {
  84. [self.confirmPasswordTextField becomeFirstResponder];
  85. return YES;
  86. }
  87. return YES;
  88. }
  89. @end