Commit 01c4de34 by 蒋勇

d

parent c540810d
...@@ -16,14 +16,17 @@ class UserCache extends CacheBase{ ...@@ -16,14 +16,17 @@ class UserCache extends CacheBase{
return "g_userlocal_" return "g_userlocal_"
} }
async buildCacheVal(cachekey,inputkey, val, ex, ...items) { async buildCacheVal(cachekey,inputkey, val, ex, ...items) {
const configValue = await this.userDao.model.findOne({ const configValue = await this.userDao.model.findAll({
where: { userName: inputkey, app_id: settings.pmappid }, where: { userName: inputkey, app_id: settings.pmappid },
attributes: ['id','userName', 'nickName','headUrl','jwtkey','jwtsecret','created_at','isSuper','isAdmin','mail'], attributes: ['id','userName', 'nickName','headUrl','jwtkey','jwtsecret','created_at','isSuper','isAdmin','mail'],
include: [{ model: this.db.models.company,raw:true}], include: [
{ model: this.db.models.company,raw:true},
{model:this.db.models.role,as:"Roles",attributes:["id","code"],}
],
}); });
if (configValue) { if (configValue && configValue[0]) {
return JSON.stringify(configValue); return JSON.stringify(configValue[0]);
} }
return null; return null;
} }
......
...@@ -7,6 +7,7 @@ class UserService extends ServiceBase { ...@@ -7,6 +7,7 @@ class UserService extends ServiceBase {
super("auth", ServiceBase.getDaoName(UserService)); super("auth", ServiceBase.getDaoName(UserService));
this.companyDao = system.getObject("db.common.companyDao"); this.companyDao = system.getObject("db.common.companyDao");
this.roleDao = system.getObject("db.auth.roleDao"); this.roleDao = system.getObject("db.auth.roleDao");
this.authS=system.getObject("service.auth.authSve");
} }
//登录后的租户创建属于租户的用户 //登录后的租户创建属于租户的用户
...@@ -115,6 +116,13 @@ class UserService extends ServiceBase { ...@@ -115,6 +116,13 @@ class UserService extends ServiceBase {
if (userfind) { if (userfind) {
let token = await self.cmakejwt(userfind.jwtkey, userfind.jwtsecret, null); let token = await self.cmakejwt(userfind.jwtkey, userfind.jwtsecret, null);
rtn.token = token; rtn.token = token;
let roleids=userfind.Roles.map(item=>{
return item.id
})
let auths= await this.authS.findAuthsByRole(roleids)
userfind["access"]=auths
delete userfind["jwtkey"] delete userfind["jwtkey"]
delete userfind["jwtsecret"] delete userfind["jwtsecret"]
rtn.user = userfind; rtn.user = userfind;
...@@ -131,6 +139,13 @@ class UserService extends ServiceBase { ...@@ -131,6 +139,13 @@ class UserService extends ServiceBase {
// include: [{ model: this.db.models.company, raw: true, attributes: ["companykey"] }] // include: [{ model: this.db.models.company, raw: true, attributes: ["companykey"] }]
// }); // });
let userfind = await this.cacheManager["UserCache"].cache(uname) let userfind = await this.cacheManager["UserCache"].cache(uname)
//添加当前用户的权限信息
let roleids=userfind.Roles.map(item=>{
return item.id
})
let auths= await this.authS.findAuthsByRole(roleids)
userfind["access"]=auths
delete userfind["jwtkey"] delete userfind["jwtkey"]
delete userfind["jwtsecret"] delete userfind["jwtsecret"]
return userfind; return userfind;
......
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