Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
a0b4a4a2
Commit
a0b4a4a2
authored
May 03, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
6226cd86
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
70 additions
and
224 deletions
+70
-224
center-manage/app/base/controller/ctl.base.js
+2
-1
center-manage/app/base/controller/impl/auth/orgCtl.js
+1
-1
center-manage/app/base/controller/impl/common/companyCtl.js
+5
-62
center-manage/app/base/db/cache/userCache.js
+1
-1
center-manage/app/base/db/impl/auth/userDao.js
+4
-6
center-manage/app/base/service/impl/auth/userSve.js
+56
-46
center-manage/app/base/service/impl/common/companySve.js
+0
-107
center-manage/app/base/system.js
+1
-0
No files found.
center-manage/app/base/controller/ctl.base.js
View file @
a0b4a4a2
...
@@ -36,11 +36,12 @@ class CtlBase {
...
@@ -36,11 +36,12 @@ class CtlBase {
}
}
async
setContextParams
(
pobj
,
qobj
,
req
)
{
async
setContextParams
(
pobj
,
qobj
,
req
)
{
let
custtags
=
req
.
headers
[
"x-consumetag"
]?
req
.
headers
[
"x-consumetag"
].
split
(
"|"
):
null
;
let
custtags
=
req
.
headers
[
"x-consumetag"
]?
req
.
headers
[
"x-consumetag"
].
split
(
"|"
):
null
;
let
lastindex
=
custtags
?
custtags
.
length
-
1
:
0
;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
req
.
xctx
=
{
req
.
xctx
=
{
appkey
:
req
.
headers
[
"xappkey"
],
//用于系统管理区分应用,比如角色
appkey
:
req
.
headers
[
"xappkey"
],
//用于系统管理区分应用,比如角色
companyid
:
custtags
?
custtags
[
0
].
split
(
"_"
)[
1
]:
null
,
companyid
:
custtags
?
custtags
[
0
].
split
(
"_"
)[
1
]:
null
,
password
:
custtags
?
custtags
[
1
].
split
(
"_"
)[
1
]:
null
,
password
:
custtags
?
custtags
[
lastindex
].
split
(
"_"
)[
1
]:
null
,
username
:
req
.
headers
[
"x-consumer-username"
],
username
:
req
.
headers
[
"x-consumer-username"
],
userid
:
req
.
headers
[
"x-consumer-custom-id"
],
userid
:
req
.
headers
[
"x-consumer-custom-id"
],
credid
:
req
.
headers
[
"x-credential-identifier"
],
credid
:
req
.
headers
[
"x-credential-identifier"
],
...
...
center-manage/app/base/controller/impl/auth/orgCtl.js
View file @
a0b4a4a2
...
@@ -7,7 +7,7 @@ const logCtl = system.getObject("web.common.oplogCtl");
...
@@ -7,7 +7,7 @@ const logCtl = system.getObject("web.common.oplogCtl");
class
OrgCtl
extends
CtlBase
{
class
OrgCtl
extends
CtlBase
{
constructor
(){
constructor
(){
super
(
"auth"
,
CtlBase
.
getServiceName
(
OrgCtl
));
super
(
"auth"
,
CtlBase
.
getServiceName
(
OrgCtl
));
this
.
compSvr
=
system
.
getObject
(
"service.common.companySve"
);
//
this.compSvr=system.getObject("service.common.companySve");
}
}
//检查是否已经存在主要岗位
//检查是否已经存在主要岗位
async
checkMainPosition
(
p
,
q
,
req
){
async
checkMainPosition
(
p
,
q
,
req
){
...
...
center-manage/app/base/controller/impl/common/companyCtl.js
View file @
a0b4a4a2
...
@@ -7,70 +7,13 @@ const CtlBase = require("../../ctl.base");
...
@@ -7,70 +7,13 @@ const CtlBase = require("../../ctl.base");
class
CompanyCtl
extends
CtlBase
{
class
CompanyCtl
extends
CtlBase
{
constructor
()
{
constructor
()
{
super
(
"common"
,
CtlBase
.
getServiceName
(
CompanyCtl
));
super
(
"common"
,
CtlBase
.
getServiceName
(
CompanyCtl
));
this
.
userS
=
system
.
getObject
(
"service.auth.userSve"
);
}
async
initNewInstance
(
pobj
,
queryobj
,
req
)
{
var
rtn
=
{};
return
system
.
getResult
(
rtn
);
}
//to do租户在创建公司的时候,需要同时维护平台下面,用户所属租户是当前租户的公司
//当删除公司时,需要同时删除公司关联的APP,还有用户关联的公司
async
create
(
p
,
q
,
req
){
var
user
=
await
this
.
userS
.
findOne
({
id
:
p
.
userid
});
var
uuidstr
=
this
.
getUUID
();
p
.
companykey
=
uuidstr
;
var
company
=
await
this
.
service
.
create
(
p
,
user
);
req
.
session
.
tocompany
=
company
;
return
system
.
getResult
(
company
);
}
}
async
update
(
p
,
q
,
req
){
async
update
(
p
,
q
,
req
){
//修改重新刷新页面,初始化页面的公司信息
let
u
=
await
super
.
update
(
p
,
q
,
req
)
var
rtn
=
await
super
.
update
(
p
,
q
,
req
);
//缓存失效
req
.
session
.
company
=
p
;
await
this
.
cacheManager
[
"CompanyCache"
].
invalidate
(
p
.
companykey
)
return
system
.
getResult
(
rtn
);
let
company
=
await
this
.
cacheManager
[
"CompanyCache"
].
cache
(
p
.
companykey
)
}
return
system
.
getResult
(
company
)
async
buyApp
(
p
,
q
,
req
){
var
cmpid
=
req
.
session
.
tocompany
.
id
;
var
user
=
req
.
session
.
user
;
var
cmpfind
=
await
this
.
service
.
buyApp
(
p
,
cmpid
,
user
);
req
.
session
.
tocompany
=
cmpfind
;
return
system
.
getResult
(
cmpfind
.
apps
);
}
async
giveupApp
(
p
,
q
,
req
){
var
comid
=
p
.
compid
;
var
appid
=
p
.
appid
;
var
rtn
=
await
this
.
service
.
giveupApp
(
comid
,
appid
);
return
system
.
getResult
(
rtn
);
}
//设置当前用户选择的公司为当前公司
async
settocompany
(
p
,
q
,
req
){
p
.
isCurrent
=
true
;
req
.
session
.
tocompany
=
p
;
var
cmp
=
await
this
.
service
.
settocompany
(
p
);
return
system
.
getResult
(
cmp
);
}
async
findAndCountAll
(
p
,
q
,
req
){
var
comps
=
await
this
.
service
.
findAndCountAll
(
p
,
q
,
req
);
var
rtns
=
[];
for
(
var
cmp
of
comps
){
if
(
cmp
.
id
!=
settings
.
platformcompanyid
){
var
rtntmp
=
{
id
:
cmp
.
id
,
name
:
cmp
.
name
,
companykey
:
cmp
.
companykey
,
description
:
cmp
.
description
,
logoUrl
:
cmp
.
logoUrl
,
isCurrent
:
cmp
.
usercompany
.
isCurrent
,
apps
:
cmp
.
apps
?
cmp
.
apps
:[]
}
rtns
.
push
(
rtntmp
);
}
}
var
rtn
=
{};
rtn
.
results
=
{
count
:
rtns
.
length
,
rows
:
rtns
};
rtn
.
aggresult
=
{};
return
system
.
getResult
(
rtn
);
}
}
}
}
module
.
exports
=
CompanyCtl
;
module
.
exports
=
CompanyCtl
;
center-manage/app/base/db/cache/userCache.js
View file @
a0b4a4a2
...
@@ -18,7 +18,7 @@ class UserCache extends CacheBase{
...
@@ -18,7 +18,7 @@ class UserCache extends CacheBase{
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
.
findOne
({
where
:
{
userName
:
inputkey
,
app_id
:
settings
.
pmappid
},
where
:
{
userName
:
inputkey
,
app_id
:
settings
.
pmappid
},
attributes
:
[
'
userName'
,
'nickName'
,
'headUrl'
,
'jwtkey'
,
'jwtsecret'
,
'created_at'
,
'isSuper'
,
'isAdmin
'
],
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
}],
});
});
...
...
center-manage/app/base/db/impl/auth/userDao.js
View file @
a0b4a4a2
...
@@ -85,21 +85,19 @@ class UserDao extends Dao{
...
@@ -85,21 +85,19 @@ class UserDao extends Dao{
return
w
;
return
w
;
}
}
async
preUpdate
(
u
){
async
preUpdate
(
u
){
if
(
u
.
roles
&&
u
.
roles
.
length
>
0
){
if
(
u
.
roles
&&
u
.
roles
.
length
>
=
0
){
var
roles
=
await
this
.
db
.
models
.
role
.
findAll
({
where
:{
id
:{[
this
.
db
.
Op
.
in
]:
u
.
roles
}}});
var
roles
=
await
this
.
db
.
models
.
role
.
findAll
({
where
:{
id
:{[
this
.
db
.
Op
.
in
]:
u
.
roles
}}});
console
.
log
(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
);
console
.
log
(
roles
);
u
.
roles
=
roles
u
.
roles
=
roles
}
}
return
u
;
return
u
;
}
}
async
update
(
obj
){
async
update
(
obj
){
var
obj2
=
await
this
.
preUpdate
(
obj
);
var
obj2
=
await
this
.
preUpdate
(
obj
);
console
.
log
(
"update...................."
);
console
.
log
(
obj2
);
await
this
.
model
.
update
(
obj2
,{
where
:{
id
:
obj2
.
id
}});
await
this
.
model
.
update
(
obj2
,{
where
:{
id
:
obj2
.
id
}});
var
user
=
await
this
.
model
.
findOne
({
where
:{
id
:
obj2
.
id
}});
var
user
=
await
this
.
model
.
findOne
({
where
:{
id
:
obj2
.
id
}});
user
.
setRoles
(
obj2
.
roles
);
if
(
obj2
.
roles
){
user
.
setRoles
(
obj2
.
roles
);
}
return
user
;
return
user
;
}
}
async
findAndCountAll
(
qobj
,
t
){
async
findAndCountAll
(
qobj
,
t
){
...
...
center-manage/app/base/service/impl/auth/userSve.js
View file @
a0b4a4a2
...
@@ -14,22 +14,22 @@ class UserService extends ServiceBase {
...
@@ -14,22 +14,22 @@ class UserService extends ServiceBase {
//和租户绑定同一家公司
//和租户绑定同一家公司
//按照用户名和密码进行注册
//按照用户名和密码进行注册
//控制器端检查用户名和密码非空
//控制器端检查用户名和密码非空
async
registerByTantent
(
p
,
q
)
{
async
registerByTantent
(
p
,
q
)
{
p
.
rolecodes
=
(
p
.
roles
&&
p
.
roles
.
length
>
0
)?
p
.
roles
:
[
settings
.
pmroleid
[
"pr"
]];
p
.
rolecodes
=
(
p
.
roles
&&
p
.
roles
.
length
>
0
)
?
p
.
roles
:
[
settings
.
pmroleid
[
"pr"
]];
let
rtn
=
await
this
.
pmregister
(
p
,
q
)
let
rtn
=
await
this
.
pmregister
(
p
,
q
)
return
rtn
;
return
rtn
;
}
}
//应用的自由用户注册,无需验证,需要前端头设置公司KEY
//应用的自由用户注册,无需验证,需要前端头设置公司KEY
async
pmregisterByFreeUser
(
p
,
q
)
{
async
pmregisterByFreeUser
(
p
,
q
)
{
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
let
rtn
=
await
this
.
pmregister
(
p
,
q
)
let
rtn
=
await
this
.
pmregister
(
p
,
q
)
return
rtn
;
return
rtn
;
}
}
//平台租户注册接口方法
//平台租户注册接口方法
//控制器端检查用户名和密码非空
//控制器端检查用户名和密码非空
async
pmregister
(
p
,
q
)
{
async
pmregister
(
p
,
q
)
{
var
self
=
this
;
var
self
=
this
;
let
tmppwd
=
p
.
password
;
let
tmppwd
=
p
.
password
;
...
@@ -37,8 +37,8 @@ class UserService extends ServiceBase {
...
@@ -37,8 +37,8 @@ class UserService extends ServiceBase {
tmppwd
=
settings
.
defaultpwd
;
tmppwd
=
settings
.
defaultpwd
;
}
}
p
.
password
=
this
.
getEncryptStr
(
tmppwd
);
p
.
password
=
this
.
getEncryptStr
(
tmppwd
);
if
(
!
p
.
nickName
)
{
if
(
!
p
.
nickName
)
{
p
.
nickName
=
p
.
userName
;
p
.
nickName
=
p
.
userName
;
}
}
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
//对于租户类型注册,创建一个默认公司,公司名称xxxx的公司
//对于租户类型注册,创建一个默认公司,公司名称xxxx的公司
...
@@ -46,25 +46,25 @@ class UserService extends ServiceBase {
...
@@ -46,25 +46,25 @@ class UserService extends ServiceBase {
let
cmpkey
=
self
.
getUUID
();
let
cmpkey
=
self
.
getUUID
();
let
rolecodes
=
p
.
rolecodes
?
p
.
rolecodes
:
[
settings
.
pmroleid
[
"ta"
]];
let
rolecodes
=
p
.
rolecodes
?
p
.
rolecodes
:
[
settings
.
pmroleid
[
"ta"
]];
if
(
rolecodes
[
0
]
==
settings
.
pmroleid
[
"ta"
])
{
//如果注册时,角色是租户,那么需要创建默认公司
if
(
rolecodes
[
0
]
==
settings
.
pmroleid
[
"ta"
])
{
//如果注册时,角色是租户,那么需要创建默认公司
p
.
isAdmin
=
true
;
//租户默认就是管理员的权限
p
.
isAdmin
=
true
;
//租户默认就是管理员的权限
let
cmp
=
await
self
.
companyDao
.
create
({
name
:
p
.
userName
+
"的公司"
,
companykey
:
cmpkey
},
t
);
let
cmp
=
await
self
.
companyDao
.
create
({
name
:
p
.
userName
+
"的公司"
,
companykey
:
cmpkey
},
t
);
p
.
company_id
=
cmp
.
id
;
p
.
company_id
=
cmp
.
id
;
}
}
//如果是用户注册,平台用户应该只属于平台应用
//如果是用户注册,平台用户应该只属于平台应用
let
roleappid
=
p
.
app_id
;
//先取出当前应用的id,给后续的取角色用,角色是按照应用和公司区分
let
roleappid
=
p
.
app_id
;
//先取出当前应用的id,给后续的取角色用,角色是按照应用和公司区分
p
.
app_id
=
settings
.
pmappid
p
.
app_id
=
settings
.
pmappid
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
//设置默认角色,租户
//设置默认角色,租户
//设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
//设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
//如果是非租户,那么按照当前应用ID是找不到指定的角色,所以是空的
//如果是非租户,那么按照当前应用ID是找不到指定的角色,所以是空的
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
},
app_id
:
roleappid
,
company_id
:
p
.
company_id
},
transaction
:
t
});
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
},
app_id
:
roleappid
,
company_id
:
p
.
company_id
},
transaction
:
t
});
if
(
roles
&&
roles
.
length
>
0
)
{
if
(
roles
&&
roles
.
length
>
0
)
{
await
u
.
setRoles
(
roles
,
{
transaction
:
t
});
await
u
.
setRoles
(
roles
,
{
transaction
:
t
});
}
}
//创建统一账号 to add extra fields
//创建统一账号 to add extra fields
let
cred
=
await
self
.
cregister
(
u
.
userName
,
p
.
company_id
,
p
.
password
,
u
.
id
+
""
)
let
cred
=
await
self
.
cregister
(
u
.
userName
,
p
.
company_id
,
p
.
password
,
u
.
id
+
""
)
console
.
log
(
"......................................"
);
console
.
log
(
"......................................"
);
console
.
log
(
cred
.
consumer
.
id
);
console
.
log
(
cred
.
consumer
.
id
);
if
(
cred
)
{
if
(
cred
)
{
...
@@ -124,7 +124,7 @@ class UserService extends ServiceBase {
...
@@ -124,7 +124,7 @@ class UserService extends ServiceBase {
}
}
})
})
}
}
async
getUserInfo
(
uname
)
{
async
getUserInfo
(
uname
)
{
// let userfind = await this.dao.model.findOne({
// let userfind = await this.dao.model.findOne({
// where: { userName: uname, app_id: settings.pmappid },
// where: { userName: uname, app_id: settings.pmappid },
// attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'],
// attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'],
...
@@ -138,10 +138,10 @@ class UserService extends ServiceBase {
...
@@ -138,10 +138,10 @@ class UserService extends ServiceBase {
//自由用户的电话登录和注册
//自由用户的电话登录和注册
//需要存在公司KEY
//需要存在公司KEY
async
pmloginByVCodeForFreeUser
(
p
,
q
)
{
async
pmloginByVCodeForFreeUser
(
p
,
q
)
{
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
let
rtn
=
await
this
.
pmloginByVCode
(
p
,
q
,
req
)
let
rtn
=
await
this
.
pmloginByVCode
(
p
,
q
,
req
)
return
system
.
getResult
(
rtn
);
return
system
.
getResult
(
rtn
);
}
}
//平台租户注册与登录
//平台租户注册与登录
...
@@ -171,11 +171,11 @@ class UserService extends ServiceBase {
...
@@ -171,11 +171,11 @@ class UserService extends ServiceBase {
return
rtn
;
return
rtn
;
}
else
{
}
else
{
//先按照用户名查续身份信息,获取key,secret,
//先按照用户名查续身份信息,获取key,secret,
let
regrtn
=
await
this
.
pmregister
({
userName
:
mobile
,
nickName
:
mobile
,
rolecodes
:
p
.
rolecodes
,
company_id
:
p
.
company_id
,
app_id
:
p
.
app_id
});
let
regrtn
=
await
this
.
pmregister
({
userName
:
mobile
,
nickName
:
mobile
,
rolecodes
:
p
.
rolecodes
,
company_id
:
p
.
company_id
,
app_id
:
p
.
app_id
});
let
token
=
await
this
.
cmakejwt
(
regrtn
.
user
.
jwtkey
,
regrtn
.
user
.
jwtsecret
,
null
);
let
token
=
await
this
.
cmakejwt
(
regrtn
.
user
.
jwtkey
,
regrtn
.
user
.
jwtsecret
,
null
);
// rtn.token = token;
// rtn.token = token;
// rtn.user = u;
// rtn.user = u;
regrtn
.
token
=
token
regrtn
.
token
=
token
return
regrtn
;
return
regrtn
;
}
}
}
}
...
@@ -194,14 +194,24 @@ class UserService extends ServiceBase {
...
@@ -194,14 +194,24 @@ class UserService extends ServiceBase {
return
vcodeobj
.
vcode
;
return
vcodeobj
.
vcode
;
}
}
//修改中心密码
//修改中心密码
async
cmodifypwd
(
uname
,
newpwd
){
async
cmodifypwd
(
uname
,
newpwd
,
cmpid
)
{
try
{
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
consumerUrl
(
uname
),
{
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
newpwd
]
},
"PATCH"
)
console
.
log
(
rtn
)
if
(
rtn
.
statusCode
==
200
)
{
return
rtn
.
data
;
}
return
null
;
}
catch
(
e
)
{
console
.
log
(
e
);
return
null
;
}
}
}
//创建统一账号及jwt身份
//创建统一账号及jwt身份
async
cregister
(
uname
,
cmpid
,
pass
,
uid
)
{
async
cregister
(
uname
,
cmpid
,
pass
,
uid
)
{
try
{
try
{
var
rtn2
=
null
;
var
rtn2
=
null
;
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),
{
username
:
uname
,
custom_id
:
uid
,
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
pass
]
})
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),
{
username
:
uname
,
custom_id
:
uid
,
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
pass
]
})
console
.
log
(
rtn
)
console
.
log
(
rtn
)
if
(
rtn
.
statusCode
==
409
)
{
if
(
rtn
.
statusCode
==
409
)
{
throw
new
Error
(
"已经存在相同的统一账号名称!"
);
throw
new
Error
(
"已经存在相同的统一账号名称!"
);
...
@@ -248,7 +258,7 @@ class UserService extends ServiceBase {
...
@@ -248,7 +258,7 @@ class UserService extends ServiceBase {
return
null
;
return
null
;
}
}
}
}
//登录统一账号
//登录统一账号
async
clogin
(
uname
)
{
async
clogin
(
uname
)
{
...
@@ -259,34 +269,34 @@ class UserService extends ServiceBase {
...
@@ -259,34 +269,34 @@ class UserService extends ServiceBase {
async
findCUser
(
uname
)
{
async
findCUser
(
uname
)
{
}
}
async
resetPassword
(
uname
,
pwd
)
{
async
resetPassword
(
uname
,
pwd
)
{
let
inpassword
=
this
.
getEncryptStr
(
pwd
);
let
inpassword
=
this
.
getEncryptStr
(
pwd
);
var
self
=
this
;
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
let
up
=
await
self
.
dao
.
updateByWhere
({
password
:
inpassword
},{
userName
:
uname
},
t
);
let
up
=
await
self
.
dao
.
updateByWhere
({
password
:
inpassword
},
{
userName
:
uname
},
t
);
//令缓存失效
//令缓存失效
await
this
.
cacheManager
[
"UserCache"
].
invalidate
(
uname
);
await
self
.
cacheManager
[
"UserCache"
].
invalidate
(
uname
);
let
cacheUser
=
await
self
.
cacheManager
[
"UserCache"
].
cache
(
uname
);
//修改认证中心的tag密码
//修改认证中心的tag密码
let
modi
=
await
self
.
cmodifypwd
(
uname
,
inpassword
,
cacheUser
.
company
.
id
)
if
(
!
modi
)
{
throw
new
Error
(
"修改中心密码出错"
)
}
let
cacheUser
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
up
.
userName
);
return
cacheUser
;
return
cacheUser
;
});
});
}
}
//修改
//修改
async
update
(
qobj
,
tm
=
null
)
{
async
update
(
qobj
,
tm
=
null
)
{
var
self
=
this
;
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
let
up
=
await
self
.
dao
.
update
(
qobj
,
t
);
let
up
=
await
self
.
dao
.
update
(
qobj
,
t
);
//令缓存失效
//令缓存失效
await
this
.
cacheManager
[
"UserCache"
].
invalidate
(
qobj
.
userName
);
await
self
.
cacheManager
[
"UserCache"
].
invalidate
(
qobj
.
userName
);
let
roles
=
await
self
.
db
.
models
.
role
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
qobj
.
roles
}
}
});
let
cacheUser
=
await
self
.
cacheManager
[
"UserCache"
].
cache
(
qobj
.
userName
);
if
(
roles
&&
roles
.
length
>
0
){
await
up
.
setRoles
(
roles
,
{
transaction
:
t
});
}
let
cacheUser
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
up
.
userName
);
return
cacheUser
;
return
cacheUser
;
});
});
}
}
}
}
...
...
center-manage/app/base/service/impl/common/companySve.js
View file @
a0b4a4a2
const
system
=
require
(
"../../../system"
);
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
uiconfig
=
system
.
getUiConfig2
(
settings
.
appKey
);
class
CompanyService
extends
ServiceBase
{
class
CompanyService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
super
(
"common"
,
ServiceBase
.
getDaoName
(
CompanyService
));
super
(
"common"
,
ServiceBase
.
getDaoName
(
CompanyService
));
this
.
userS
=
system
.
getObject
(
"service.auth.userSve"
);
}
async
create
(
p
,
user
){
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
){
var
company
=
await
self
.
dao
.
model
.
create
(
p
,{
transaction
:
t
});
await
user
.
addCompany
(
company
,{
transaction
:
t
});
//先按照用户id,取消所有当前
var
up1
=
await
self
.
db
.
models
.
usercompany
.
update
({
isCurrent
:
false
},{
where
:{
user_id
:
user
.
id
},
transaction
:
t
});
//按照用户id和公司id,设置当前
var
up2
=
await
self
.
db
.
models
.
usercompany
.
update
({
isCurrent
:
true
},{
where
:{
user_id
:
user
.
id
,
company_id
:
company
.
id
},
transaction
:
t
});
return
company
;
});
}
async
delete
(
pobj
){
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
){
//查询出要删除的租户
var
usercomp
=
await
self
.
db
.
models
.
usercompany
.
findOne
({
where
:{
user_id
:
pobj
.
userid
,
company_id
:
pobj
.
id
}});
await
usercomp
.
destroy
({
where
:{
user_id
:
pobj
.
userid
,
company_id
:
pobj
.
id
},
transaction
:
t
});
//to 删除公司选择的应用
await
self
.
db
.
models
.
companyapp
.
destroy
({
where
:{
company_id
:
pobj
.
id
},
transaction
:
t
});
var
rtn
=
await
self
.
dao
.
delete
({
id
:
pobj
.
id
},
t
);
//按照公司ID,查询当前user表里是否有记录,如果已经有,就不要删除记录todo
return
rtn
;
});
}
async
giveupApp
(
comid
,
appid
){
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
){
//检查当前company_id下面是否有用户存在,如果已经存在就不要删除了
var
c
=
await
self
.
db
.
models
.
user
.
count
({
where
:{
owner_id
:
comid
}});
if
(
c
>
1
){
return
null
;
}
else
{
if
(
c
==
1
){
await
self
.
db
.
models
.
user
.
destroy
({
where
:{
owner_id
:
comid
},
force
:
true
});
}
await
self
.
db
.
models
.
companyapp
.
destroy
({
where
:{
company_id
:
comid
,
app_id
:
appid
}});
return
{};
}
});
}
async
buyApp
(
p
,
cmid
,
user
){
var
self
=
this
;
var
appid
=
p
.
id
;
var
cmid
=
cmid
;
return
this
.
db
.
transaction
(
async
function
(
t
){
//先按照用户id,取消所有当前
// var cmp=await self.db.models.company.findOne({where:{
// id:cmid,
// }});
// cmp.addApp(p,{transaction:t});
var
seladd
=
await
self
.
db
.
models
.
companyapp
.
create
({
company_id
:
cmid
,
app_id
:
appid
},{
transaction
:
t
});
//创建当前购买应用的管理员账号,设置所属公司,不需要建立公司关系在在中间表
var
appadminuser
=
await
self
.
userS
.
createAdminUser
({
userName
:
user
.
userName
,
password
:
user
.
password
,
mobile
:
user
.
mobile
,
app_id
:
appid
,
owner_id
:
cmid
,
tanentor_id
:
user
.
id
,
//租户的id
},{
transaction
:
t
});
//查询当前公司,关联出apps
var
cmpfind
=
await
self
.
db
.
models
.
company
.
findOne
({
where
:{
id
:
cmid
,
},
include
:[
{
model
:
self
.
db
.
models
.
app
}
],
transaction
:
t
});
return
cmpfind
;
});
}
async
settocompany
(
p
){
var
self
=
this
;
var
uid
=
p
.
userid
;
var
cid
=
p
.
id
;
return
this
.
db
.
transaction
(
async
function
(
t
){
//先按照用户id,取消所有当前
var
up1
=
await
self
.
db
.
models
.
usercompany
.
update
({
isCurrent
:
false
},{
where
:{
user_id
:
uid
},
transaction
:
t
});
//按照用户id和公司id,设置当前
var
up2
=
await
self
.
db
.
models
.
usercompany
.
update
({
isCurrent
:
true
},{
where
:{
user_id
:
uid
,
company_id
:
cid
},
transaction
:
t
});
return
p
;
});
}
async
findAndCountAll
(
p
,
q
,
req
){
var
u
=
await
this
.
userS
.
dao
.
model
.
findOne
({
where
:{
id
:
p
.
userid
},
include
:
[
{
model
:
this
.
db
.
models
.
company
,
through
:{
attributes
:[
'isCurrent'
]},
include
:[
{
model
:
this
.
db
.
models
.
app
}
]
},
]
});
var
cmps
=
await
u
.
companies
;
return
cmps
;
}
}
}
}
module
.
exports
=
CompanyService
;
module
.
exports
=
CompanyService
;
center-manage/app/base/system.js
View file @
a0b4a4a2
...
@@ -74,6 +74,7 @@ class System {
...
@@ -74,6 +74,7 @@ class System {
},
},
body
:
data
body
:
data
},
function
(
error
,
response
,
body
)
{
},
function
(
error
,
response
,
body
)
{
console
.
log
(
error
)
rtn
.
statusCode
=
response
.
statusCode
rtn
.
statusCode
=
response
.
statusCode
if
(
!
error
)
{
if
(
!
error
)
{
if
(
body
){
if
(
body
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment