Browse Source

1.登录的封装
2.信息的提取

time 6 years ago
parent
commit
45f90b9b25

+ 1 - 1
UU_Ent/UU_Ent.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
   s.name     = "UU_Ent"
-  s.version  = "0.0.1"
+  s.version  = "0.0.2"
   s.license  = "Apache License, Version 2.0"
   s.authors  = { 'gRPC contributors' => 'grpc-io@googlegroups.com' }
   s.homepage = "https://grpc.io/"

+ 8 - 5
UU_Ent/UU_Ent.xcodeproj/project.pbxproj

@@ -20,6 +20,7 @@
 		2710E66A228166990002A4B0 /* mine_route.json in Resources */ = {isa = PBXBuildFile; fileRef = 2710E669228166990002A4B0 /* mine_route.json */; };
 		2710E66E2281746E0002A4B0 /* UIPopoverListView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2710E66D2281746E0002A4B0 /* UIPopoverListView.m */; };
 		3FE47A8D89A70D18F98B1E41 /* libPods-UU_EntUITests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F4F857DEEC69AEDCFACDFD51 /* libPods-UU_EntUITests.a */; };
+		991C1464228275B70080B54A /* YRLoginManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 991C1463228275B70080B54A /* YRLoginManager.m */; };
 		9948171422783494007C7CEA /* msg_route.json in Resources */ = {isa = PBXBuildFile; fileRef = 9948171322783494007C7CEA /* msg_route.json */; };
 		9948171722785013007C7CEA /* YRWorkTabCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9948171622785013007C7CEA /* YRWorkTabCell.m */; };
 		9948171A22785044007C7CEA /* YRWorkCollCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9948171922785044007C7CEA /* YRWorkCollCell.m */; };
@@ -168,6 +169,8 @@
 		49A8B37D50A80EFFD84620EC /* Pods-UU_EntTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UU_EntTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-UU_EntTests/Pods-UU_EntTests.release.xcconfig"; sourceTree = "<group>"; };
 		49D3F089EECE8E3EDF7D2E1C /* Pods-UU_EntUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UU_EntUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-UU_EntUITests/Pods-UU_EntUITests.release.xcconfig"; sourceTree = "<group>"; };
 		71B4DF45C8EC3368ACFC4193 /* Pods-UU_Ent.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UU_Ent.debug.xcconfig"; path = "Pods/Target Support Files/Pods-UU_Ent/Pods-UU_Ent.debug.xcconfig"; sourceTree = "<group>"; };
+		991C1462228275B70080B54A /* YRLoginManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YRLoginManager.h; sourceTree = "<group>"; };
+		991C1463228275B70080B54A /* YRLoginManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YRLoginManager.m; sourceTree = "<group>"; };
 		994817112278281F007C7CEA /* macro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = macro.h; sourceTree = "<group>"; };
 		994817122278290A007C7CEA /* import.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = import.h; sourceTree = "<group>"; };
 		9948171322783494007C7CEA /* msg_route.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = msg_route.json; sourceTree = "<group>"; };
@@ -423,6 +426,8 @@
 		2710E671228175390002A4B0 /* Others */ = {
 			isa = PBXGroup;
 			children = (
+				991C1462228275B70080B54A /* YRLoginManager.h */,
+				991C1463228275B70080B54A /* YRLoginManager.m */,
 			);
 			path = Others;
 			sourceTree = "<group>";
@@ -634,11 +639,8 @@
 		99C6FE8D22768EC000C7070A /* Utils */ = {
 			isa = PBXGroup;
 			children = (
-
 				2710E66B2281744C0002A4B0 /* UIPopoverListView */,
-
 				99B4252C22815E0700DAE304 /* AlertView */,
-
 				2710E65A22801D870002A4B0 /* UINavigation */,
 				2710E65922801D760002A4B0 /* UITextField */,
 				999F651B227E6A3E00329012 /* NSString */,
@@ -1316,7 +1318,7 @@
 			files = (
 			);
 			inputPaths = (
-				"${PODS_ROOT}/Target Support Files/Pods-UU_Ent/Pods-UU_Ent-resources.sh",
+				"${SRCROOT}/Pods/Target Support Files/Pods-UU_Ent/Pods-UU_Ent-resources.sh",
 				"${PODS_ROOT}/IQKeyboardManager/IQKeyboardManager/Resources/IQKeyboardManager.bundle",
 				"${PODS_ROOT}/MJRefresh/MJRefresh/MJRefresh.bundle",
 				"${PODS_CONFIGURATION_BUILD_DIR}/gRPC/gRPCCertificates.bundle",
@@ -1329,7 +1331,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-UU_Ent/Pods-UU_Ent-resources.sh\"\n";
+			shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-UU_Ent/Pods-UU_Ent-resources.sh\"\n";
 			showEnvVarsInLog = 0;
 		};
 		A2F6040888740937A057571A /* [CP] Check Pods Manifest.lock */ = {
@@ -1362,6 +1364,7 @@
 				99C6FF232276E4C000C7070A /* YRMsgMainCell.m in Sources */,
 				2710E66E2281746E0002A4B0 /* UIPopoverListView.m in Sources */,
 				99C16345228027C8002ED79D /* YRMsgHeader.m in Sources */,
+				991C1464228275B70080B54A /* YRLoginManager.m in Sources */,
 				99C6FECB227696CA00C7070A /* YRMsgVC.m in Sources */,
 				99C16340227FD24E002ED79D /* YRWorkConModel.m in Sources */,
 				99C6FF262276FAE000C7070A /* YRMsgMainModel.m in Sources */,

+ 21 - 84
UU_Ent/UU_Ent/Modules/Login/Main/Controllers/YRLoginVC.m

@@ -9,7 +9,7 @@
 #import "YRLoginVC.h"
 #import "YRUserInfo.h"
 #import "YRRegisterVC.h"
-#import <UU_Ent/Account.pbrpc.h>
+#import "YRLoginManager.h"
 
 @interface YRLoginVC ()<UITextFieldDelegate,UIPopoverListViewDelegate,UIPopoverListViewDataSource>
 @property (nonatomic,strong) UIScrollView *scrollView;
@@ -28,70 +28,31 @@
    
 }
 
-#pragma mark --- 保存账号密码进沙盒
--(void)saveUserDataToNSUserDefaults
-{
-    [[NSUserDefaults standardUserDefaults] setObject:FORMAT(@"%@",_phoneTF.text) forKey:@"userAccount"];
-    
-    [[NSUserDefaults standardUserDefaults] setObject:FORMAT(@"%@",_passwordTF.text) forKey:@"userPassword"];
-}
 
 #pragma mark --- 登录操作
 -(void)loginAction
 {
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-    
-    [GRPCCall useInsecureConnectionsForHost:kHostAddress];
-    
-    AccountService *client = [[AccountService alloc]initWithHost:kHostAddress];
-    
-    AccountSigninRequest *request = [AccountSigninRequest message];
-    
-    DeviceInfo *model = [DeviceInfo new];
-    
-    model.os = DeviceInfo_OS_Ios;
-    
-    request.deviceInfo = model;
-    
-    request.mobile = _phoneTF.text;
-    
-    request.password = _passwordTF.text;
-    
-    [client signinWithRequest:request handler:^(AccountSigninResponse * _Nullable response, NSError * _Nullable error) {
-        
-        [MBProgressHUD hideHUDForView:self.view animated:YES];
 
-        if (response.responseHeader.success) {
-            
-            [YRUserInfo shareManager].masChanged = YES;
-            
-            NSDictionary *resDic = response.mj_keyValues;
-            
-            [YRUserInfo shareManager].token = response.authedToken.token;
-            
-            [YRUserInfo shareManager].userInfo = resDic;
+    [YRLoginManager userLoginWithPhone:_phoneTF.text passWord:_passwordTF.text success:^(AccountSigninResponse * _Nullable response) {
+        [MBProgressHUD hideHUDForView:self.view animated:YES];
+        /*用户绑定的企业大于1个时,提供选择公司登陆*/
+        if (response.companyArray.count > 1) {
             
-            [self saveUserDataToNSUserDefaults];
+            [self setSelectCompanyUI];
             
-            /*用户绑定的企业大于1个时,提供选择公司登陆*/
-            if (response.companyArray.count > 1) {
+        }else{
+            /*只有一个企业时,直接登录*/
+            if (self.completed) {
                 
-                [self setSelectCompanyUI];
+                self.completed(YES);
                 
-            }else{
-                /*只有一个企业时,直接登录*/
-                if (self.completed) {
-                    
-                    self.completed(YES);
-                    
-                }
             }
-            
-        }else{
-            
-            
         }
         
+    } failure:^(AccountSigninResponse * _Nullable response, NSError * _Nullable error) {
+        [MBProgressHUD hideHUDForView:self.view animated:YES];
+        //提示错误信息
         
     }];
 }
@@ -101,43 +62,19 @@
 {
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     
-    [GRPCCall useInsecureConnectionsForHost:kHostAddress];
-    
-    AccountService *client = [[AccountService alloc]initWithHost:kHostAddress];
-    
-    SwitchCompanyRequest *request = [SwitchCompanyRequest message];
-    
-    request.companyId = [[dic objectForKey:@"id_p"] integerValue];
-    
-    GRPCProtoCall *call = [client RPCToswitchCompanyWithRequest:request handler:^(SwitchCompanyResponse * _Nullable response, NSError * _Nullable error) {
+    [YRLoginManager companyLoginWithCompanyInfo:dic success:^(SwitchCompanyResponse * _Nullable response) {
         
-        [MBProgressHUD hideHUDForView:self.view animated:YES];
-        
-        if (response.responseHeader.success) {
-            
-            [YRUserInfo shareManager].masChanged = YES;
-            
-            NSDictionary *resDic = response.mj_keyValues;
-            
-            [YRUserInfo shareManager].token = response.authedToken.token;
-            
-            [YRUserInfo shareManager].userCompanyInfo = resDic;
-            
-            if (self.completed) {
-                
-                self.completed(YES);
-                
-            }
-            
-        }else{
+        if (self.completed) {
             
+            self.completed(YES);
             
         }
+        
+    } failure:^(SwitchCompanyResponse * _Nullable response, NSError * _Nullable error) {
+       
+        //提示错误信息
+        
     }];
-    
-    call.requestHeaders[@"authentication"] = [YRUserInfo shareManager].token;
-    
-    [call start];
 }
 
 #pragma mark --- UIPopoverListView Delegate : 公司选择

+ 34 - 0
UU_Ent/UU_Ent/Modules/Login/Main/Others/YRLoginManager.h

@@ -0,0 +1,34 @@
+//
+//  YRLoginManager.h
+//  UU_Ent
+//
+//  Created by liujl on 2019/5/8.
+//  Copyright © 2019 UAS. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <UU_Ent/Account.pbrpc.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface YRLoginManager : NSObject
+
+/**
+ 自动登录
+
+ */
++(void)autoLoginsuccess:(void(^)(void))success failure:(void(^)(NSString *errorStr))failure;
+
+/**
+ 用户账号密码登录
+ */
++(void)userLoginWithPhone:(NSString *)phoneNumber passWord:(NSString *)pwd success:(void(^)(AccountSigninResponse * _Nullable response))success failure:(void(^)(AccountSigninResponse * _Nullable response, NSError * _Nullable error))failure;
+
+/**
+ 选择公司登录
+ */
++(void)companyLoginWithCompanyInfo:(NSDictionary *)company success:(void(^)(SwitchCompanyResponse * _Nullable response))success failure:(void(^)(SwitchCompanyResponse * _Nullable response, NSError * _Nullable error))failure;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 208 - 0
UU_Ent/UU_Ent/Modules/Login/Main/Others/YRLoginManager.m

@@ -0,0 +1,208 @@
+//
+//  YRLoginManager.m
+//  UU_Ent
+//
+//  Created by liujl on 2019/5/8.
+//  Copyright © 2019 UAS. All rights reserved.
+//
+
+#import "YRLoginManager.h"
+#import "YRUserInfo.h"
+
+@implementation YRLoginManager
+
++(void)autoLoginsuccess:(void(^)(void))success failure:(void(^)(NSString *errorStr))failure{
+    
+    NSString *phone = FORMAT(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userAccount"]);
+    
+    NSString *pwd = FORMAT(@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userPassword"]);
+    
+    if (phone.length != 11 || pwd.length == 0) {
+        
+        if (failure) {
+            
+            failure(@"程序出错");
+            
+        }
+        
+        return;
+        
+    }
+    //登录管理平台
+    [self userLoginWithPhone:phone passWord:pwd success:^(AccountSigninResponse * _Nullable response) {
+        //只有一家公司,不用再选择账套
+        if (response.companyArray.count == 1) {
+            
+            if (success) {
+                
+                success();
+                
+            }
+            
+        }else{
+            //登录公司
+            [self companyLoginWithCompanyInfo:[YRUserInfo shareManager].lastCompanyInfo success:^(SwitchCompanyResponse * _Nullable response) {
+                
+                if (success) {
+                    
+                    success();
+                    
+                }
+                
+            } failure:^(SwitchCompanyResponse * _Nullable response, NSError * _Nullable error) {
+                
+                if (failure) {
+                    
+                    failure(response.responseHeader.message);
+                    
+                }
+                
+            }];
+            
+        }
+        
+    } failure:^(AccountSigninResponse * _Nullable response, NSError * _Nullable error) {
+        
+        if (failure) {
+            
+            failure(response.responseHeader.message);
+            
+        }
+        
+    }];
+    
+}
+
+/**
+ 用户账号密码登录
+ */
++(void)userLoginWithPhone:(NSString *)phoneNumber passWord:(NSString *)pwd success:(void(^)(AccountSigninResponse * _Nullable response))success failure:(void(^)(AccountSigninResponse * _Nullable response, NSError * _Nullable error))failure{
+    
+    [GRPCCall useInsecureConnectionsForHost:kHostAddress];
+    
+    AccountService *client = [[AccountService alloc]initWithHost:kHostAddress];
+    
+    AccountSigninRequest *request = [AccountSigninRequest message];
+    
+    DeviceInfo *model = [DeviceInfo new];
+    
+    model.os = DeviceInfo_OS_Ios;
+    
+    request.deviceInfo = model;
+    
+    request.mobile = phoneNumber;
+    
+    request.password = pwd;
+    
+    [YRUserInfo shareManager].phoneNumber = phoneNumber;
+    
+    [client signinWithRequest:request handler:^(AccountSigninResponse * _Nullable response, NSError * _Nullable error) {
+        
+        
+        if (response.responseHeader.success) {
+            
+            [YRUserInfo shareManager].masChanged = YES;
+            
+            NSDictionary *resDic = response.mj_keyValues;
+            
+            [YRUserInfo shareManager].token = response.authedToken.token;
+            
+            [YRUserInfo shareManager].userInfo = resDic;
+            
+            [self saveUserDataToNSUserDefaultsWithPhone:phoneNumber password:pwd];
+            
+            if (response.companyArray.count == 1) {
+                
+                [YRUserInfo shareManager].currCompanyInfo = response.companyArray[0].mj_keyValues;
+                
+                [YRUserInfo shareManager].lastCompanyInfo = response.companyArray[0].mj_keyValues;
+                
+            }
+            
+            if (success) {
+                
+                success(response);
+                
+            }
+            
+        }else{
+            
+            if (failure) {
+                
+                failure(response,error);
+                
+            }
+            
+        }
+        
+        
+    }];
+    
+    
+    
+}
+
+/**
+ 选择公司登录
+ */
++(void)companyLoginWithCompanyInfo:(NSDictionary *)company success:(void(^)(SwitchCompanyResponse * _Nullable response))success failure:(void(^)(SwitchCompanyResponse * _Nullable response, NSError * _Nullable error))failure{
+    
+    [GRPCCall useInsecureConnectionsForHost:kHostAddress];
+    
+    AccountService *client = [[AccountService alloc]initWithHost:kHostAddress];
+    
+    SwitchCompanyRequest *request = [SwitchCompanyRequest message];
+    
+    request.companyId = [[company objectForKey:@"id_p"] integerValue];
+    
+    GRPCProtoCall *call = [client RPCToswitchCompanyWithRequest:request handler:^(SwitchCompanyResponse * _Nullable response, NSError * _Nullable error) {
+        
+        if (response.responseHeader.success) {
+            
+            [YRUserInfo shareManager].masChanged = YES;
+            
+            NSDictionary *resDic = response.mj_keyValues;
+            
+            [YRUserInfo shareManager].token = response.authedToken.token;
+            
+            [YRUserInfo shareManager].userCompanyInfo = resDic;
+            
+            [YRUserInfo shareManager].currCompanyInfo = company;
+            
+            [YRUserInfo shareManager].lastCompanyInfo = company;
+            
+            
+            if (success) {
+                
+                success(response);
+                
+            }
+            
+        }else{
+            
+            if (failure) {
+                
+                failure(response,error);
+                
+            }
+            
+            
+        }
+    }];
+    
+    call.requestHeaders[@"authentication"] = [YRUserInfo shareManager].token;
+    
+    [call start];
+    
+    
+}
+
+#pragma mark --- 保存账号密码进沙盒
++(void)saveUserDataToNSUserDefaultsWithPhone:(NSString *)phoneNumber  password:(NSString *)pwd
+{
+    [[NSUserDefaults standardUserDefaults] setObject:FORMAT(@"%@",phoneNumber) forKey:@"userAccount"];
+    
+    [[NSUserDefaults standardUserDefaults] setObject:FORMAT(@"%@",pwd) forKey:@"userPassword"];
+}
+
+@end

+ 1 - 1
UU_Ent/UU_Ent/Modules/Message/Main/Controllers/YRMsgVC.m

@@ -26,7 +26,7 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
-    
+    DLog(@"%@",[YRUserInfo shareManager].userCompanyInfo);
 }
 
 -(void)viewWillAppear:(BOOL)animated{

+ 14 - 0
UU_Ent/UU_Ent/Modules/Mine/Main/Others/YRUserInfo.h

@@ -19,6 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
  */
 @property(copy,nonatomic)NSString *token;
 
+/**
+ 用户手机号
+ */
+@property(copy,nonatomic)NSString *phoneNumber;
+
 /**
  登录返回的账户所有信息
  */
@@ -29,6 +34,15 @@ NS_ASSUME_NONNULL_BEGIN
  */
 @property(strong,nonatomic)NSDictionary *userCompanyInfo;
 
+/**
+ 当前正在登录中的公司信息
+ */
+@property(strong,nonatomic)NSDictionary *currCompanyInfo;
+/**
+ 最后登录的公司信息
+ */
+@property(strong,nonatomic)NSDictionary *lastCompanyInfo;
+
 /**
  是否切换账套
  */

+ 23 - 6
UU_Ent/UU_Ent/Modules/Mine/Main/Others/YRUserInfo.m

@@ -11,19 +11,36 @@
 @implementation YRUserInfo
 
 +(instancetype)shareManager{
-    
+
     static YRUserInfo *instance = nil;
-    
+
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
-        
+
         instance = [YRUserInfo new];
-       
-        
+
+
     });
-    
+
     return instance;
+
+}
+
+-(void)setLastCompanyInfo:(NSDictionary *)lastCompanyInfo{
+    
+    if (lastCompanyInfo) {
+        
+        [[NSUserDefaults standardUserDefaults] setObject:lastCompanyInfo forKey:@"UUCompanyLastCompanyInfo"];
+        
+    }
+    
     
 }
 
+
+-(NSDictionary *)lastCompanyInfo{
+
+    return [[NSUserDefaults standardUserDefaults] objectForKey:@"UUCompanyLastCompanyInfo"];
+
+}
 @end

+ 2 - 0
UU_Ent/UU_Ent/Modules/Work/Main/Models/YRWorkConModel.m

@@ -61,6 +61,8 @@
     
 }
 
+
+
 @end
 
 

+ 0 - 1
UU_Ent/UU_Ent/Utils/UIPopoverListView/UIPopoverListView.m

@@ -459,7 +459,6 @@ BOOL isfirstOpen=YES;
     if (self.delegate && [self.delegate respondsToSelector:@selector(popoverListViewCancel:)]) {
         [self.delegate popoverListViewCancel:self];
     }
-    DLog(@"Cancel!!!!!!!");
     // dismiss self
     [self dismiss];
 }