123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // UserRestPasswordViewController.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/30.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XenonSDK.h"
- #import "UserRestPasswordViewController.h"
- #import "UserRestPassword2ViewController.h"
- //
- //private var users: [String: Bool] = [:]
- @interface UserRestPasswordViewController ()
- @property (nonatomic, strong) NSMutableDictionary* users;
- @end
- @implementation UserRestPasswordViewController
- - (NSInteger)smsType {
- return 2;
- }
- - (void)securityCodeForPrepare:(id)sender {
- // Resign editing.
- [self.view endEditing:YES];
-
- // Must enter phone.
- NSString* phone = self.phoneTextField.text;
- if (phone.length == 0) {
- [XSNetwork showHudFailure:@"请输入手机号"];
- return;
- }
-
- if (!sdk_verifyPhone(phone)) {
- [XSNetwork showHudFailure:@"请输入正确的手机号格式"];
- return;
- }
-
- // If the account has never been registered, an error message appears.
- void (^handler1)(void) = ^{
-
- id qq = XenonSDK.sharedSDK.configuration.fixLinkQQ ?: @"";
- id tel = XenonSDK.sharedSDK.configuration.fixLinkTel ?: @"";
-
- NSString* str = [NSString stringWithFormat:@"\n该手机暂未绑定任何帐号, 如果需要修改帐号密码请与人工客服联系, 给您带来的不便敬请见谅。\n\n客服QQ: %@\n客服电话: %@\n\n", qq, tel];
-
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:str preferredStyle:UIAlertControllerStyleAlert];
- [alert addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:nil]];
- [self presentViewController:alert animated:YES completion:nil];
- };
- // Send SMS security code.
- void (^handler2)(void) = ^{
- [super securityCodeForPrepare:sender];
- };
- // Result map.
- NSDictionary<NSNumber*, void(^)(void)>* mapper = @{@0: handler1, @1: handler2};
- // Read cache results first.
- id status = self.users[phone];
- if (status != nil) {
- mapper[status]();
- return;
- }
-
- // Check user with phone.
- [XSNetwork checkWithPhone:phone complete:^(id object, NSError *error) {
-
- // Got it wrong.
- if (error != nil) {
- [XSNetwork showHudFailure:error];
- return;
- }
-
- // Cache.
- NSInteger dstatus = !![object[@"status"] boolValue];
- self.users[phone] = @(dstatus);
- mapper[@(dstatus)]();
- }];
- }
- - (void)securityCodeForVerify:(id)sender {
- [super securityCodeForVerify:sender];
-
- // Must enter phone.
- NSString* phone = self.phoneTextField.text;
- if (phone.length == 0) {
- [XSNetwork showHudFailure:@"请输入手机号"];
- return;
- }
-
- if (!sdk_verifyPhone(phone)) {
- [XSNetwork showHudFailure:@"请输入正确的手机号格式"];
- return;
- }
-
- NSString* code = self.securityCodeTextField.text;
- if (code.length == 0) {
- [XSNetwork showHudFailure:@"请输入验证码"];
- return;
- }
-
- UserRestPassword2ViewController* viewController = [[UserRestPassword2ViewController alloc] init];
- [self.navigationController pushViewController:viewController animated:YES];
- viewController.phone = phone;
- viewController.code = code;
- }
- @end
|