UserRestPasswordViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // UserRestPasswordViewController.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 "UserRestPasswordViewController.h"
  10. #import "UserRestPassword2ViewController.h"
  11. //
  12. //private var users: [String: Bool] = [:]
  13. @interface UserRestPasswordViewController ()
  14. @property (nonatomic, strong) NSMutableDictionary* users;
  15. @end
  16. @implementation UserRestPasswordViewController
  17. - (NSInteger)smsType {
  18. return 2;
  19. }
  20. - (void)securityCodeForPrepare:(id)sender {
  21. // Resign editing.
  22. [self.view endEditing:YES];
  23. // Must enter phone.
  24. NSString* phone = self.phoneTextField.text;
  25. if (phone.length == 0) {
  26. [XSNetwork showHudFailure:@"请输入手机号"];
  27. return;
  28. }
  29. if (!sdk_verifyPhone(phone)) {
  30. [XSNetwork showHudFailure:@"请输入正确的手机号格式"];
  31. return;
  32. }
  33. // If the account has never been registered, an error message appears.
  34. void (^handler1)(void) = ^{
  35. id qq = XenonSDK.sharedSDK.configuration.fixLinkQQ ?: @"";
  36. id tel = XenonSDK.sharedSDK.configuration.fixLinkTel ?: @"";
  37. NSString* str = [NSString stringWithFormat:@"\n该手机暂未绑定任何帐号, 如果需要修改帐号密码请与人工客服联系, 给您带来的不便敬请见谅。\n\n客服QQ: %@\n客服电话: %@\n\n", qq, tel];
  38. UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:str preferredStyle:UIAlertControllerStyleAlert];
  39. [alert addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:nil]];
  40. [self presentViewController:alert animated:YES completion:nil];
  41. };
  42. // Send SMS security code.
  43. void (^handler2)(void) = ^{
  44. [super securityCodeForPrepare:sender];
  45. };
  46. // Result map.
  47. NSDictionary<NSNumber*, void(^)(void)>* mapper = @{@0: handler1, @1: handler2};
  48. // Read cache results first.
  49. id status = self.users[phone];
  50. if (status != nil) {
  51. mapper[status]();
  52. return;
  53. }
  54. // Check user with phone.
  55. [XSNetwork checkWithPhone:phone complete:^(id object, NSError *error) {
  56. // Got it wrong.
  57. if (error != nil) {
  58. [XSNetwork showHudFailure:error];
  59. return;
  60. }
  61. // Cache.
  62. NSInteger dstatus = !![object[@"status"] boolValue];
  63. self.users[phone] = @(dstatus);
  64. mapper[@(dstatus)]();
  65. }];
  66. }
  67. - (void)securityCodeForVerify:(id)sender {
  68. [super securityCodeForVerify:sender];
  69. // Must enter phone.
  70. NSString* phone = self.phoneTextField.text;
  71. if (phone.length == 0) {
  72. [XSNetwork showHudFailure:@"请输入手机号"];
  73. return;
  74. }
  75. if (!sdk_verifyPhone(phone)) {
  76. [XSNetwork showHudFailure:@"请输入正确的手机号格式"];
  77. return;
  78. }
  79. NSString* code = self.securityCodeTextField.text;
  80. if (code.length == 0) {
  81. [XSNetwork showHudFailure:@"请输入验证码"];
  82. return;
  83. }
  84. UserRestPassword2ViewController* viewController = [[UserRestPassword2ViewController alloc] init];
  85. [self.navigationController pushViewController:viewController animated:YES];
  86. viewController.phone = phone;
  87. viewController.code = code;
  88. }
  89. @end