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
2b0242df
Commit
2b0242df
authored
Apr 24, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
36da0228
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
41 deletions
+81
-41
center-manage/app/base/api/api.base.js
+2
-2
center-manage/app/base/controller/ctl.base.js
+26
-3
center-manage/app/base/controller/impl/auth/userCtl.js
+4
-4
center-manage/app/base/db/cache/appCache.js
+18
-23
center-manage/app/base/db/cache/companyCache.js
+28
-0
center-manage/app/base/service/impl/auth/userSve.js
+3
-9
No files found.
center-manage/app/base/api/api.base.js
View file @
2b0242df
...
@@ -11,12 +11,12 @@ class APIBase{
...
@@ -11,12 +11,12 @@ class APIBase{
console
.
log
(
req
.
headers
)
console
.
log
(
req
.
headers
)
let
custtags
=
req
.
headers
[
"x-consumetag"
].
split
(
"|"
);
let
custtags
=
req
.
headers
[
"x-consumetag"
].
split
(
"|"
);
req
.
xctx
=
{
req
.
xctx
=
{
appkey
:
req
.
headers
[
"x-appkey"
],
appkey
:
req
.
headers
[
"x-app
-
key"
],
companyid
:
custtags
[
0
].
split
(
"_"
)[
1
],
companyid
:
custtags
[
0
].
split
(
"_"
)[
1
],
password
:
custtags
[
1
].
split
(
"_"
)[
1
],
password
:
custtags
[
1
].
split
(
"_"
)[
1
],
username
:
req
.
headers
[
"x-consumer-username"
],
username
:
req
.
headers
[
"x-consumer-username"
],
credid
:
req
.
headers
[
"x-credential-identifier"
],
credid
:
req
.
headers
[
"x-credential-identifier"
],
companykey
:
req
.
headers
[
"x-company-key"
],
companykey
:
req
.
headers
[
"x-company-key"
],
//这个头没有必要,因为来访companyid有值了
}
}
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
return
rtn
;
return
rtn
;
...
...
center-manage/app/base/controller/ctl.base.js
View file @
2b0242df
...
@@ -26,18 +26,41 @@ class CtlBase {
...
@@ -26,18 +26,41 @@ 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
;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
req
.
xctx
=
{
req
.
xctx
=
{
appkey
:
req
.
headers
[
"x-app-key"
],
appkey
:
req
.
headers
[
"x-app-key"
],
//用于系统管理区分应用,比如角色
companyid
:
custtags
?
custtags
[
0
].
split
(
"_"
)[
1
]:
null
,
companyid
:
custtags
?
custtags
[
0
].
split
(
"_"
)[
1
]:
null
,
password
:
custtags
?
custtags
[
1
].
split
(
"_"
)[
1
]:
null
,
password
:
custtags
?
custtags
[
1
].
split
(
"_"
)[
1
]:
null
,
username
:
req
.
headers
[
"x-consumer-username"
],
username
:
req
.
headers
[
"x-consumer-username"
],
credid
:
req
.
headers
[
"x-credential-identifier"
],
credid
:
req
.
headers
[
"x-credential-identifier"
],
companykey
:
req
.
headers
[
"x-company-key"
],
companykey
:
req
.
headers
[
"x-company-key"
],
//专用于自由用户注册,自由用户用于一定属于某个存在的公司
}
if
(
!
req
.
xctx
.
appkey
){
return
[
-
200
,
"请求头缺少应用x-app-key"
]
}
else
{
let
app
=
await
this
.
cacheManager
[
"AppCache"
].
cache
(
req
.
xctx
.
appkey
);
req
.
xctx
.
appid
=
app
.
id
;
pobj
.
app_id
=
app
.
id
;
//传递参数对象里注入app_id
}
//平台注册时,companyid,companykey都为空
//自由注册时,companykey不能为空
// if(!req.xctx.companyid && !req.xctx.companykey){
// return [-200,"请求头缺少应用x-app-key"]
// }
if
(
!
req
.
xctx
.
companyid
&&
creq
.
xctx
.
companykey
){
let
comptmp
=
await
this
.
cacheManager
[
"CompanyCache"
].
cache
(
req
.
xctx
.
companykey
);
req
.
xctx
.
companyid
=
comptmp
.
id
;
}
if
(
req
.
xctx
.
companyid
){
//在请求传递数据对象注入公司id
pobj
.
company_id
=
req
.
xctx
.
companyid
;
}
}
}
}
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
try
{
try
{
await
this
.
setContextParams
(
pobj
,
query
,
req
);
let
xarg
=
await
this
.
setContextParams
(
pobj
,
query
,
req
);
if
(
xarg
[
0
]
<
0
){
return
system
.
getResultFail
(...
xarg
);
}
//从请求头里面取appkey_consumename
//从请求头里面取appkey_consumename
// var consumeName=req.headers[""]
// var consumeName=req.headers[""]
// var appkey=
// var appkey=
...
...
center-manage/app/base/controller/impl/auth/userCtl.js
View file @
2b0242df
...
@@ -29,9 +29,10 @@ class UserCtl extends CtlBase {
...
@@ -29,9 +29,10 @@ class UserCtl extends CtlBase {
if
(
!
pobj
.
userName
||
!
pobj
.
password
)
{
if
(
!
pobj
.
userName
||
!
pobj
.
password
)
{
return
system
.
getResult
(
null
,
"请检查用户名和密码是否存在"
)
return
system
.
getResult
(
null
,
"请检查用户名和密码是否存在"
)
}
}
p
.
companykey
=
req
.
xctx
.
companykey
;
//p.company_id = req.xctx.companyid;//控制基类里已经添加
if
(
!
p
.
companykey
)
{
return
system
.
getResult
(
null
,
"自有用户创建需要提供公司KEY"
);
if
(
!
p
.
company_id
)
{
return
system
.
getResultFail
(
-
201
,
"自有用户创建需要提供公司KEY"
);
}
}
let
rtn
=
await
this
.
service
.
pmregisterByFreeUser
(
p
,
q
);
let
rtn
=
await
this
.
service
.
pmregisterByFreeUser
(
p
,
q
);
return
rtn
;
return
rtn
;
...
@@ -47,7 +48,6 @@ class UserCtl extends CtlBase {
...
@@ -47,7 +48,6 @@ class UserCtl extends CtlBase {
if
(
!
pobj
.
userName
||
!
pobj
.
password
)
{
if
(
!
pobj
.
userName
||
!
pobj
.
password
)
{
return
system
.
getResult
(
null
,
"请检查用户名和密码是否存在"
)
return
system
.
getResult
(
null
,
"请检查用户名和密码是否存在"
)
}
}
p
.
company_id
=
req
.
xctx
.
companyid
;
let
rtn
=
await
this
.
service
.
registerByTantent
(
p
,
q
);
let
rtn
=
await
this
.
service
.
registerByTantent
(
p
,
q
);
return
rtn
;
return
rtn
;
}
}
...
...
center-manage/app/base/db/cache/appCache.js
View file @
2b0242df
const
CacheBase
=
require
(
"../cache.base"
);
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
const
settings
=
require
(
"../../../config/settings"
);
//缓存首次登录的赠送的宝币数量
class
AppCache
extends
CacheBase
{
class
AppCache
extends
CacheBase
{
constructor
(){
constructor
()
{
super
();
super
();
this
.
prefix
=
"g_centerappkey:"
;
this
.
appDao
=
system
.
getObject
(
"db.common.appDao"
);
}
}
// isdebug() {
isdebug
(){
// return settings.env == "dev";
return
settings
.
env
==
"dev"
;
// }
desc
()
{
return
"应用服务实体缓存"
;
}
}
prefix
()
{
desc
()
{
return
"
g_vcode_"
return
"
缓存本地应用对象"
;
}
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
prefix
(){
//inputkey采用appkey_mobile的形式
return
"g_applocal_"
var
mobile
=
inputkey
;
var
tmplCode
=
val
;
var
signName
=
items
?
items
[
0
]
:
""
;
var
vcode
=
await
this
.
smsUtil
.
getUidStr
(
6
,
10
);
if
(
!
tmplCode
&&
!
signName
)
{
this
.
smsUtil
.
sendMsg
(
mobile
,
vcode
);
}
//tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else
{
this
.
smsUtil
.
aliSendMsg
(
mobile
,
tmplCode
,
signName
,
JSON
.
stringify
({
code
:
vcode
}));
}
}
return
JSON
.
stringify
({
vcode
:
vcode
});
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
const
configValue
=
await
this
.
appDao
.
findOne
({
where
:{
appkey
:
inputkey
}});
if
(
configValue
)
{
return
JSON
.
stringify
(
configValue
);
}
return
null
;
}
}
}
}
module
.
exports
=
VCode
Cache
;
module
.
exports
=
App
Cache
;
\ No newline at end of file
center-manage/app/base/db/cache/companyCache.js
0 → 100644
View file @
2b0242df
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
class
CompanyCache
extends
CacheBase
{
constructor
(){
super
();
this
.
prefix
=
"g_centercompanykey:"
;
this
.
companyDao
=
system
.
getObject
(
"db.common.companyDao"
);
}
isdebug
(){
return
settings
.
env
==
"dev"
;
}
desc
(){
return
"缓存统一公司对象"
;
}
prefix
(){
return
"gc_companylocal_"
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
const
configValue
=
await
this
.
companyDao
.
findOne
({
where
:{
companykey
:
inputkey
}});
if
(
configValue
)
{
return
JSON
.
stringify
(
configValue
);
}
return
null
;
}
}
module
.
exports
=
CompanyCache
;
\ No newline at end of file
center-manage/app/base/service/impl/auth/userSve.js
View file @
2b0242df
...
@@ -48,19 +48,13 @@ class UserService extends ServiceBase {
...
@@ -48,19 +48,13 @@ class UserService extends ServiceBase {
if
(
rolecodes
[
0
]
==
settings
.
pmroleid
[
"ta"
])
{
//如果注册时,角色是租户,那么需要创建默认公司
if
(
rolecodes
[
0
]
==
settings
.
pmroleid
[
"ta"
])
{
//如果注册时,角色是租户,那么需要创建默认公司
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
;
}
else
{
if
(
!
p
.
company_id
){
cmpkey
=
p
.
companykey
;
//否则是租户协助创建个人访客,采用租户获得的公司key
//按照公司key,获取公司 to do cache
let
compfind
=
await
self
.
companyDao
.
model
.
findOne
({
where
:
{
companykey
:
cmpkey
},
transaction
:
t
})
p
.
company_id
=
compfind
.
id
;
}
}
}
//p.company_id----已经在控制器基类中设置
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
let
u
=
await
self
.
dao
.
create
(
p
,
t
)
//设置默认角色,租户
//设置默认角色,租户
//设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
//设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
}
}
},
transaction
:
t
});
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
}
}
,
app_id
:
p
.
app_id
,
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
});
}
}
...
@@ -165,7 +159,7 @@ class UserService extends ServiceBase {
...
@@ -165,7 +159,7 @@ class UserService extends ServiceBase {
return
rtn
;
return
rtn
;
}
else
{
}
else
{
//先按照用户名查续身份信息,获取key,secret,
//先按照用户名查续身份信息,获取key,secret,
let
u
=
await
this
.
pmregister
({
userName
:
mobile
,
nickName
:
mobile
,
rolecodes
:
p
.
rolecodes
,
company
key
:
p
.
companykey
});
let
u
=
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
(
u
.
jwtkey
,
u
.
jwtsecret
,
null
);
let
token
=
await
this
.
cmakejwt
(
u
.
jwtkey
,
u
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
rtn
.
token
=
token
;
rtn
.
user
=
u
;
rtn
.
user
=
u
;
...
...
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