UserRestPassword2ViewController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. @interface UserRestPassword2ViewController () <UITextFieldDelegate>
  12. @end
  13. @implementation UserRestPassword2ViewController
  14. - (void)setNewPasswordTextField:(id)sender {
  15. self.passwordTextField = sender;
  16. }
  17. - (void)sdk_dismissViewController:(id)sender {
  18. if (self.navigationController.viewControllers.count > 2) {
  19. // if viewControllers[1] is UserRestPasswordViewController {
  20. // navigationController?.popToViewController(viewControllers[0], animated: true)
  21. // return
  22. // }
  23. }
  24. return [super sdk_dismissViewController:sender];
  25. }
  26. - (void)displayModeForPassword:(UIButton*)sender {
  27. // Toggle password display mode.
  28. sender.selected = !sender.selected;
  29. if (self.passwordTextField.tag == sender.tag) {
  30. self.passwordTextField.secureTextEntry = sender.selected;
  31. }
  32. if (self.confirmPasswordTextField.tag == sender.tag) {
  33. self.confirmPasswordTextField.secureTextEntry = sender.selected;
  34. }
  35. }
  36. - (void)securityCodeForReset:(id)sender {
  37. [self.view endEditing:YES];
  38. NSString* phone = self.phone;
  39. NSString* code = self.code;
  40. NSString* newPassword = self.passwordTextField.text;
  41. NSString* confirmPassword = self.confirmPasswordTextField.text;
  42. if (newPassword.length == 0) {
  43. [XSNetwork showHudFailure:@"请输入新的密码"];
  44. return;
  45. }
  46. if (confirmPassword.length == 0) {
  47. [XSNetwork showHudFailure:@"请再次输入新的密码"];
  48. return;
  49. }
  50. if (![newPassword isEqual:confirmPassword]) {
  51. [XSNetwork showHudFailure:@"两次输入的密码不一致"];
  52. return;
  53. }
  54. [XSNetwork showHudLoading];
  55. [XSNetwork resetWithPhone:phone code:code password:newPassword complete:^(id object, NSError *error) {
  56. if (error != nil) {
  57. [XSNetwork showHudFailure:error];
  58. return;
  59. }
  60. [XSNetwork showHudSuccess:@"密码修改成功"];
  61. if (self.navigationController.viewControllers.count <= 2) {
  62. [self.navigationController popViewControllerAnimated:YES];
  63. return ;
  64. }
  65. UIViewController* pop = self.navigationController.viewControllers[self.navigationController.viewControllers.count - 2 - 1];
  66. [self.navigationController popToViewController:pop animated:YES];
  67. }];
  68. }
  69. - (BOOL)textFieldShouldReturn:(UITextField*)textField {
  70. if (textField.returnKeyType == UIReturnKeyDone) {
  71. return NO;
  72. }
  73. if (textField == self.passwordTextField) {
  74. [self.confirmPasswordTextField becomeFirstResponder];
  75. return YES;
  76. }
  77. return YES;
  78. }
  79. @end