소스 검색

添加自动登录

桂欢 1 년 전
부모
커밋
2bf368b1b3

+ 28 - 4
SLAiELTS/SLAiELTS/AppDelegate.mm

@@ -9,6 +9,7 @@
 #import "IQKeyboardManager.h"
 #import "SLLoginVCViewController.h"
 #import "SLBaseTabBarController.h"
+#import "SLRoleLabelViewController.h"
 
 @interface AppDelegate ()
 
@@ -21,16 +22,37 @@
     // Override point for customization after application launch.
     self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
     self.window.backgroundColor = [UIColor whiteColor];
+    self.window.rootViewController = [[SLBaseViewController alloc] init];
     [SLHttpCenter SharedInstance].serverUrl = @"http://dlchat.zheke.com";
 //    [SLHttpCenter SharedInstance].serverUrl = @"http://10.0.0.14:8088";
-//    SLBaseTabBarController *baseVc = [[SLBaseTabBarController alloc] init];
-    UIViewController *vc = [SLLoginVCViewController loadViewControllewWithNib];
-    self.window.rootViewController = [[SLBaseNavigationController alloc] initWithRootViewController:vc];
-    [self.window makeKeyAndVisible];
+    NSString *userPhone = [[NSUserDefaults standardUserDefaults] objectForKey:@"SLUserPhone"];
+    NSString *userPassword = [[NSUserDefaults standardUserDefaults] objectForKey:@"SLUserPassword"];
+    if (userPassword.length) {
+        NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:@{@"phone" : userPhone, @"password" : userPassword, @"code" : @"0"}];
+        [self cacheLoginWhit:parameter];
+    }else {
+        [self setLoginVcWithRootWindow];
+    }
     [self buildIQkeyBoard];
     return YES;
 }
 
+- (void)cacheLoginWhit:(NSDictionary *)parameter {
+    [[SLHttpCenter SharedInstance] postWithUrl:@"/api/Token/LoginApp" parameter:parameter success:^(id responseObject) {
+        NSDictionary *dataDict = [responseObject objectForKey:@"data"];
+        SLLoginInfo *loginModel = [SLLoginInfo mj_objectWithKeyValues:dataDict];
+        [SLGlobalInfo SharedInstance].loginInfo = loginModel;
+        [SLUserModel requestUserRoleModel];
+        if (!loginModel.isAiData) {
+            [self setLoginVcWithRootWindow];
+        }else {
+            [self setTabWithRootWindow];
+        }
+    } failure:^(SPRequestError *error) {
+        [self setLoginVcWithRootWindow];
+    }];
+}
+
 - (void)setTabWithRootWindow {
     SLBaseTabBarController *tabBarContr = [[SLBaseTabBarController alloc] init];
     self.window.rootViewController = [[SLBaseNavigationController alloc] initWithRootViewController:tabBarContr];;
@@ -38,6 +60,8 @@
 }
 
 - (void)setLoginVcWithRootWindow {
+    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"SLUserPassword"];
+    [[NSUserDefaults standardUserDefaults] synchronize];
     UIViewController *vc = [SLLoginVCViewController loadViewControllewWithNib];
     self.window.rootViewController = [[SLBaseNavigationController alloc] initWithRootViewController:vc];;
     [self.window makeKeyAndVisible];

+ 2 - 1
SLAiELTS/SLAiELTS/ViewControllers/LoginVC/SLLoginVCViewController.m

@@ -48,7 +48,6 @@
     //  获取到clearbutton 可以获取样式上
     UIButton *btn = [self.phoneTextField valueForKey:@"_clearButton"];
     [btn setImage:ImageName(@"icon_clear_circle") forState:UIControlStateNormal];
-    self.protocolBtn.selected = YES;
     self.view.backgroundColor = [UIColor whiteColor];
 }
 
@@ -106,6 +105,8 @@
         NSDictionary *dataDict = [responseObject objectForKey:@"data"];
         SLLoginInfo *loginModel = [SLLoginInfo mj_objectWithKeyValues:dataDict];
         [SLGlobalInfo SharedInstance].loginInfo = loginModel;
+        [[NSUserDefaults standardUserDefaults] setObject:codeStr forKey:@"SLUserPassword"];
+        [[NSUserDefaults standardUserDefaults] synchronize];
         [SLUserModel requestUserRoleModel];
         if (!loginModel.isAiData) {
             SLRoleLabelViewController *vc = [SLRoleLabelViewController loadViewControllewWithNib];

+ 2 - 0
SLAiELTS/SLAiELTS/ViewControllers/LoginVC/SLRegistViewController.m

@@ -96,6 +96,8 @@
         NSDictionary *dataDict = [responseObject objectForKey:@"data"];
         SLLoginInfo *loginModel = [SLLoginInfo mj_objectWithKeyValues:dataDict];
         [SLGlobalInfo SharedInstance].loginInfo = loginModel;
+        [[NSUserDefaults standardUserDefaults] setObject:codeStr forKey:@"SLUserPassword"];
+        [[NSUserDefaults standardUserDefaults] synchronize];
         [SLUserModel requestUserRoleModel];
         SLRoleLabelViewController *vc = [SLRoleLabelViewController loadViewControllewWithNib];
         [self.navigationController pushViewController:vc animated:YES];