Commit 5959242c authored by Achilles's avatar Achilles

add authorizedorgs

parent 109f149b
......@@ -159,17 +159,15 @@
@implementation ICRSystemHeaderView (Configure)
- (void)updateWithUserUtil {
// ICRUserUtil *userUtil = [ICRUserUtil sharedInstance];
// [self updateWithCompanyName:userUtil.orgName
// companyIcon:nil
// user:userUtil.displayName
// code:userUtil.orgCode];
- (void)updateWithUserUtil {
VankeCommonModel *userModel = [VankeCommonModel sharedInstance];
User *user = [userModel currentUser];
Enterpirse *ent = [userModel currentEnterprise];
LoginResponseData *data = [userModel getLoginInfo];
if (nil == data) {
return;
}
User *user = [data getUser];
Enterpirse *ent = [data getEnterprise];
[self updateWithCompanyName:ent.name
companyIcon:nil
user:user.name
......
......@@ -9,11 +9,8 @@
#ifndef VankeConfig_h
#define VankeConfig_h
// 当前用户
#define KEY_CURRENT_USER @"VANKE_CUR_USER"
// 当前企业
#define KEY_CURRENT_ENT @"VANKE_CUR_ENT"
// 当前用户信息
#define KEY_CURRENT_USER_INFO @"VANKE_CUR_USER_INFO"
// 当前用户密码
#define KEY_CURRENT_USER_PWD @"VANKE_CUR_USER_PWD"
......
......@@ -58,7 +58,7 @@
}
-(VankeBaseAPI*) addEnterpriseIdToHeader: (BeeHTTPRequest*) req {
Enterpirse *ent = [[VankeCommonModel sharedInstance] currentEnterprise];
Enterpirse *ent = [[VankeCommonModel sharedInstance] currentEnt];
if (nil != ent && ![VankeUtil isBlankString:ent.uuid]) {
req.HEADER(@"enterprise", ent.uuid);
}
......
......@@ -47,6 +47,20 @@
@end
// 授权组织
@interface AuthorizedOrg : BeeActiveObject
// 标识
@property (nonatomic, strong) NSString *uuid;
// 代码
@property (nonatomic, strong) NSString *code;
// 名称
@property (nonatomic, strong) NSString *name;
// 图片
@property (nonatomic, strong) NSString *picture;
@end
// 登录响应数据
@interface LoginResponseData : BeeActiveObject
......@@ -72,26 +86,15 @@
// 企业认证码
@property (nonatomic, strong) NSString *authenticode;
// 授权组织
@property (nonatomic, strong) NSArray *authorizedOrgs;
-(User*) getUser;
-(Enterpirse*) getEnterprise;
@end
// 授权组织
@interface AuthorizedOrg : BeeActiveObject
// 标识
@property (nonatomic, strong) NSString *uuid;
// 代码
@property (nonatomic, strong) NSString *code;
// 名称
@property (nonatomic, strong) NSString *name;
// 图片
@property (nonatomic, strong) NSString *picture;
@end
// 登录请求返回
@interface LoginResponse : VankeResponse
@property (nonatomic, strong) LoginResponseData *data;
......
......@@ -24,7 +24,7 @@
return;
}
NSString *url = [NSString stringWithFormat:@"/user/login/%@", self.userName];
NSString *url = [NSString stringWithFormat:@"/wanke/user/login/%@", self.userName];
NSString *encryptPwd = [VankeUtil md5: self.password];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
self.authenticode, @"authenticode",
......@@ -95,6 +95,9 @@
@synthesize enterprise_code;
@synthesize enterprise_name;
@synthesize authenticode;
@synthesize authorizedOrgs;
CONVERT_PROPERTY_CLASS(authorizedOrgs, AuthorizedOrg)
-(User*) getUser {
if ([VankeUtil isBlankString:self.user_uuid]) {
......
......@@ -16,17 +16,55 @@
AS_SINGLETON(VankeCommonModel)
- (void) saveLoginUser: (User*) user password: (NSString*) password enterprise: (Enterpirse*) enterprise;
/**
* 保存登录信息
*
* @param info 登录请求响应,传入nil表示清空当前人员信息
* @param password 密码
*/
- (void) saveLoginInfo: (LoginResponseData*) info password: (NSString*) password;
/**
* 取得当前登录人员信息
*
* @return 人员信息,找不到返回nil
*/
- (LoginResponseData*) getLoginInfo;
/**
* 删除当前登录信息
*/
- (void) removeLoginInfo;
/**
* 当前登录人员基本信息
*
* @return 人员基本信息,找不到返回nil.
*/
- (User*) currentUser;
- (Enterpirse*) currentEnterprise;
/**
* 当前登录人员的所属组织信息
*
* @return 组织基本信息,找不到返回nil.
*/
- (Enterpirse*) currentEnt;
/**
* 当前人员的授权组织列表
*
* @return 组织列表,找不到nil
*/
-(NSArray*) getAuthOrgs;
- (NSString*) currentUserPassword;
/**
* 当前登录人员的登录密码
*
* @return 明文密码,找不到返回nil.
*/
- (NSString*) currentUserPwd;
- (void) removeCurrentUser;
-(NSArray*) getAuthorizedOrgs;
@end
......
......@@ -16,47 +16,57 @@
DEF_SINGLETON(VankeCommonModel)
- (void) saveLoginUser: (User*) user password: (NSString*) password enterprise: (Enterpirse*) enterprise {
if (nil != user) {
[self userDefaultsWrite:[user objectToDictionary] forKey:KEY_CURRENT_USER];
}
if (nil != enterprise) {
[self userDefaultsWrite:[enterprise objectToDictionary] forKey:KEY_CURRENT_ENT];
- (void) saveLoginInfo: (LoginResponseData*) info password: (NSString*) password {
if (nil == info) {
[self removeLoginInfo];
return;
}
[self userDefaultsWrite:[info objectToDictionary] forKey:KEY_CURRENT_USER_INFO];
[self keychainWrite:password forKey:KEY_CURRENT_USER_PWD];
}
- (User*) currentUser {
NSDictionary *dict = [self userDefaultsRead:KEY_CURRENT_USER];
- (LoginResponseData*) getLoginInfo {
NSDictionary *dict = [self userDefaultsRead:KEY_CURRENT_USER_INFO];
if (nil == dict) {
return nil;
}
return [User objectFromDictionary: dict];
return [LoginResponseData objectFromDictionary: dict];
}
- (Enterpirse*) currentEnterprise {
NSDictionary *dict = [self userDefaultsRead:KEY_CURRENT_ENT];
if (nil == dict) {
return nil;
}
return [Enterpirse objectFromDictionary: dict];
- (void) removeLoginInfo {
[self userDefaultsRemove:KEY_CURRENT_USER_INFO];
[self keychainDelete:KEY_CURRENT_USER_PWD];
}
- (NSString*) currentUserPassword {
return [self keychainRead:KEY_CURRENT_USER_PWD];
- (User*) currentUser {
LoginResponseData *data = [self getLoginInfo];
if (nil != data) {
return [data getUser];
} else {
return nil;
}
}
- (void) removeCurrentUser {
[self userDefaultsRemove:KEY_CURRENT_USER];
[self userDefaultsRemove:KEY_CURRENT_ENT];
[self keychainDelete:KEY_CURRENT_USER_PWD];
- (Enterpirse*) currentEnt {
LoginResponseData *data = [self getLoginInfo];
if (nil != data) {
return [data getEnterprise];
} else {
return nil;
}
}
-(NSArray*) getAuthorizedOrgs {
-(NSArray*) getAuthOrgs {
// LoginResponseData *data = [self getLoginInfo];
// if (nil != data) {
// return data.authorizedOrgs;
// } else {
// return nil;
// }
// TODO FOR TEST
NSMutableArray *ary = [[NSMutableArray alloc] initWithCapacity:20];
for( int i = 0; i < 20; ++i) {
AuthorizedOrg *org = [[AuthorizedOrg alloc] init];
......@@ -69,4 +79,8 @@ DEF_SINGLETON(VankeCommonModel)
return ary;
}
- (NSString*) currentUserPwd {
return [self keychainRead:KEY_CURRENT_USER_PWD];
}
@end
......@@ -77,7 +77,7 @@
-(void) autoLogin {
User *curUser = [[VankeCommonModel sharedInstance] currentUser];
NSString *userName = curUser.code;
NSString *password = [[VankeCommonModel sharedInstance] currentUserPassword];
NSString *password = [[VankeCommonModel sharedInstance] currentUserPwd];
[self login:userName password:password];
}
......@@ -85,12 +85,9 @@
LoginResponse *resp = [self getServerResp];
if (nil == resp || nil == resp.data) {
return;
} else {
[[VankeCommonModel sharedInstance] saveLoginInfo:resp.data password:password];
}
LoginResponseData *respData = resp.data;
User *user = [respData getUser];
Enterpirse *ent = [respData getEnterprise];
[[VankeCommonModel sharedInstance] saveLoginUser:user password:password enterprise:ent];
}
@end
......@@ -44,7 +44,7 @@ DEF_OUTLET( BeeUIButton, btnServiceApply )
- (void)load
{
VankeCommonModel *userModel = [VankeCommonModel sharedInstance];
authorizedOrgs = [userModel getAuthorizedOrgs];
authorizedOrgs = [userModel getAuthOrgs];
}
- (void)unload
......
......@@ -100,7 +100,7 @@ ON_LOAD_DATAS( signal )
User *user = [userModel currentUser];
if (nil != user) {
$(self.txtUserName).DATA(user.code);
$(self.txtPwd).DATA([userModel currentUserPassword]);
$(self.txtPwd).DATA([userModel currentUserPwd]);
} else {
[self.txtUserName becomeFirstResponder];
}
......
......@@ -187,7 +187,7 @@ ON_DID_APPEAR( signal )
-(void) doLogout {
// 删除当前用户
VankeCommonModel *userModel = [VankeCommonModel sharedInstance];
[userModel removeCurrentUser];
[userModel removeLoginInfo];
[self postNotification:self.SUCC_LOGOUT];
}
......
......@@ -128,7 +128,7 @@ ON_DID_DISAPPEAR( signal )
VankeCommonModel *userModel = [VankeCommonModel sharedInstance];
User *user = [userModel currentUser];
Enterpirse *ent = [userModel currentEnterprise];
Enterpirse *ent = [userModel currentEnt];
switch (indexPath.section) {
case 0:
......@@ -219,7 +219,7 @@ ON_DID_DISAPPEAR( signal )
-(void) doLogout {
// 删除当前用户
VankeCommonModel *userModel = [VankeCommonModel sharedInstance];
[userModel removeCurrentUser];
[userModel removeLoginInfo];
[self postNotification:self.SUCC_LOGOUT];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment