Skip to content

Commit db1c5bf

Browse files
committed
账号设置里面添加「关闭两步验证」功能
1 parent d9b6195 commit db1c5bf

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

Coding_iOS/Controllers/Login/Close2FAViewController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
#import "BaseViewController.h"
1010

1111
@interface Close2FAViewController : BaseViewController
12-
+ (id)vcWithPhone:(NSString *)phone sucessBlock:(void(^)())block;
12+
+ (id)vcWithPhone:(NSString *)phone sucessBlock:(void(^)(UIViewController *vc))block;
1313
@end

Coding_iOS/Controllers/Login/Close2FAViewController.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
@interface Close2FAViewController ()<UITableViewDataSource, UITableViewDelegate>
1515
@property (strong, nonatomic) NSString *phone, *phoneCode;
16-
@property (copy, nonatomic) void (^sucessBlock)();
16+
@property (copy, nonatomic) void (^sucessBlock)(UIViewController *vc);
1717

1818
@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView;
1919
@property (strong, nonatomic) UIButton *footerBtn;
2020
@property (strong, nonatomic) NSString *phoneCodeCellIdentifier;
2121
@end
2222

2323
@implementation Close2FAViewController
24-
+ (id)vcWithPhone:(NSString *)phone sucessBlock:(void (^)())block{
24+
+ (id)vcWithPhone:(NSString *)phone sucessBlock:(void (^)(UIViewController *vc))block{
2525
Close2FAViewController *vc = [self new];
2626
vc.phone = [phone isPhoneNo]? phone: nil;
2727
vc.sucessBlock = block;
@@ -136,7 +136,7 @@ - (void)footerBtnClicked:(id)sender{
136136
if (data) {
137137
[NSObject showHudTipStr:@"两步验证已关闭"];
138138
if (self.sucessBlock) {
139-
self.sucessBlock();
139+
self.sucessBlock(self);
140140
}
141141
}
142142
}];

Coding_iOS/Controllers/Login/LoginViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ - (void)sendActivateEmail{
459459
- (IBAction)cannotLoginBtnClicked:(id)sender {
460460
UIViewController *vc;
461461
if (_is2FAUI) {
462-
vc = [Close2FAViewController vcWithPhone:self.myLogin.email sucessBlock:^{
462+
vc = [Close2FAViewController vcWithPhone:self.myLogin.email sucessBlock:^(UIViewController *vc) {
463463
self.is2FAUI = NO;
464464
[self.navigationController popToRootViewControllerAnimated:YES];
465465
}];

Coding_iOS/Controllers/MeSetting/SettingAccountViewController.m

+20-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
#import "SettingPhoneViewController.h"
1616
#import "Coding_NetAPIManager.h"
1717
#import "Login.h"
18+
#import "Close2FAViewController.h"
1819

1920
@interface SettingAccountViewController ()
2021
@property (strong, nonatomic) User *myUser;
21-
2222
@property (strong, nonatomic) UITableView *myTableView;
23+
@property (assign, nonatomic) BOOL is2FAOpen;
2324
@end
2425

2526
@implementation SettingAccountViewController
@@ -53,12 +54,23 @@ - (void)viewWillAppear:(BOOL)animated{
5354
[super viewWillAppear:animated];
5455
self.myUser = [Login curLoginUser];
5556
[self.myTableView reloadData];
57+
[self refresh2FA];
58+
}
59+
60+
- (void)refresh2FA{
61+
__weak typeof(self) weakSelf = self;
62+
[[Coding_NetAPIManager sharedManager] get_is2FAOpenBlock:^(BOOL data, NSError *error) {
63+
if (!error) {
64+
weakSelf.is2FAOpen = data;
65+
[weakSelf.myTableView reloadData];
66+
}
67+
}];
5668
}
5769

5870
#pragma mark TableM
5971

6072
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
61-
return 3;
73+
return _is2FAOpen? 4: 3;
6274
}
6375

6476
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
@@ -95,7 +107,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
95107
}
96108
}else{
97109
TitleDisclosureCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleDisclosure forIndexPath:indexPath];
98-
[cell setTitleStr:@"修改密码"];
110+
[cell setTitleStr:indexPath.section == 2? @"修改密码": @"关闭两步验证"];
99111
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
100112
return cell;
101113
}
@@ -137,6 +149,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
137149
SettingPasswordViewController *vc = [[SettingPasswordViewController alloc] init];
138150
vc.myUser = self.myUser;
139151
[self.navigationController pushViewController:vc animated:YES];
152+
}else if (indexPath.section == 3){
153+
Close2FAViewController *vc = [Close2FAViewController vcWithPhone:_myUser.phone sucessBlock:^(UIViewController *vcc) {
154+
[vcc.navigationController popToRootViewControllerAnimated:YES];
155+
}];
156+
[self.navigationController pushViewController:vc animated:YES];
140157
}
141158
}
142159

Coding_iOS/Controllers/RootControllers/BaseViewController.m

+13-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ typedef NS_ENUM(NSInteger, AnalyseMethodType) {
4141
AnalyseMethodTypeForceCreate
4242
};
4343

44+
#pragma mark - UIViewController (Dismiss)
45+
@interface UIViewController (Dismiss)
46+
- (void)dismissModalVC;
47+
@end
48+
@implementation UIViewController (Dismiss)
49+
- (void)dismissModalVC{
50+
[self dismissViewControllerAnimated:YES completion:nil];
51+
}
52+
@end
53+
54+
#pragma mark - BaseViewController
55+
4456
@interface BaseViewController ()
4557

4658
@end
@@ -401,7 +413,7 @@ + (void)presentVC:(UIViewController *)viewController{
401413
}
402414
UINavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:viewController];
403415
if (!viewController.navigationItem.leftBarButtonItem) {
404-
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:viewController action:@selector(dismissModalViewControllerAnimated:)];
416+
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:viewController action:@selector(dismissModalVC)];
405417
}
406418
[[self presentingVC] presentViewController:nav animated:YES completion:nil];
407419
}

Coding_iOS/Util/Manager/Coding_NetAPIManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ typedef NS_ENUM(NSInteger, PurposeType) {
246246
#pragma mark - 2FA
247247
- (void)post_Close2FAGeneratePhoneCode:(NSString *)phone block:(void (^)(id data, NSError *error))block;
248248
- (void)post_Close2FAWithPhone:(NSString *)phone code:(NSString *)code block:(void (^)(id data, NSError *error))block;
249+
- (void)get_is2FAOpenBlock:(void (^)(BOOL data, NSError *error))block;
249250

250251
#pragma mark - Topic HotKey
251252
- (void)request_TopicHotkeyWithBlock:(void (^)(id data, NSError *error))block;

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

+6
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,12 @@ - (void)post_Close2FAWithPhone:(NSString *)phone code:(NSString *)code block:(vo
25762576
}];
25772577
}
25782578

2579+
- (void)get_is2FAOpenBlock:(void (^)(BOOL data, NSError *error))block{
2580+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:@"api/user/2fa/method" withParams:nil withMethodType:Get andBlock:^(id data, NSError *error) {
2581+
block([data[@"data"] isEqualToString:@"totp"], error);
2582+
}];
2583+
}
2584+
25792585
#pragma mark -
25802586
#pragma mark Topic HotKey
25812587

0 commit comments

Comments
 (0)