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
69f1a82c
Commit
69f1a82c
authored
Dec 17, 2020
by
Sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: autologin
parent
934ace67
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
100 deletions
+88
-100
center-manage/app/base/service/impl/auth/authSve.js
+34
-37
center-manage/app/base/service/impl/common/channelhandlers/baidu.js
+1
-0
center-manage/app/base/service/impl/common/channelhandlers/zc360.js
+1
-0
center-manage/app/config/routes/api.js
+52
-63
No files found.
center-manage/app/base/service/impl/auth/authSve.js
View file @
69f1a82c
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
class
AuthService
extends
ServiceBase
{
constructor
(){
super
(
"auth"
,
ServiceBase
.
getDaoName
(
AuthService
));
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
class
AuthService
extends
ServiceBase
{
constructor
()
{
super
(
"auth"
,
ServiceBase
.
getDaoName
(
AuthService
));
}
//字符串数组参数
//前端角色查询,按照来源应用和来源公司查询
async
findAuthsByRole
(
roleids
,
appid
,
comid
)
{
async
findAuthsByRole
(
roleids
,
appid
,
comid
)
{
//{where:{id:{[this.db.Op.in]:ids}}}
//var newattrs=rolecodestr.split(",");
var
aths
=
await
this
.
dao
.
model
.
findAll
({
attributes
:[
"bizcode"
,
"authstrs"
,
"codepath"
],
where
:{
role_id
:{[
this
.
db
.
Op
.
in
]:
roleids
}}});
//因为是按照角色ID,所以不需要按照公司
// where:{role_id:{[this.db.Op.in]:roleids},app_id:appid,company_id:comid}});
var
aths
=
await
this
.
dao
.
model
.
findAll
({
attributes
:
[
"bizcode"
,
"authstrs"
,
"codepath"
],
where
:
{
role_id
:
{
[
this
.
db
.
Op
.
in
]:
roleids
}
}
});
//因为是按照角色ID,所以不需要按照公司
// where:{role_id:{[this.db.Op.in]:roleids},app_id:appid,company_id:comid}});
return
aths
;
}
async
saveAuths
(
auths
,
appid
,
cmid
){
//先按照code 和 bizcode查询
var
self
=
this
;
console
.
log
(
"yyyyyyyyyvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
);
console
.
log
(
auths
);
return
self
.
db
.
transaction
(
async
function
(
t
){
for
(
var
i
=
0
;
i
<
auths
.
length
;
i
++
){
var
tmpAuth
=
auths
[
i
];
tmpAuth
.
app_id
=
appid
;
tmpAuth
.
company_id
=
cmid
;
var
objrtn
=
await
self
.
dao
.
model
.
findOrCreate
({
defaults
:
tmpAuth
,
where
:{
role_id
:
tmpAuth
.
role_id
,
bizcode
:
tmpAuth
.
bizcode
},
//注意这里bizcode存储的是节点的code值
transaction
:
t
,
});
console
.
log
(
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
);
console
.
log
(
objrtn
);
if
(
!
objrtn
[
1
].
created
){
//就执行更新操作
await
objrtn
[
0
].
update
(
tmpAuth
,{
where
:{
role_id
:
tmpAuth
.
role_id
,
bizcode
:
tmpAuth
.
bizcode
},
transaction
:
t
})
}
}
var
aths
=
await
self
.
dao
.
model
.
findAll
({
where
:{
role_id
:
tmpAuth
.
role_id
,
app_id
:
tmpAuth
.
app_id
},
transaction
:
t
});
return
aths
;
});
async
saveAuths
(
auths
,
appid
,
cmid
)
{
//先按照code 和 bizcode查询
var
self
=
this
;
return
self
.
db
.
transaction
(
async
function
(
t
)
{
for
(
var
i
=
0
;
i
<
auths
.
length
;
i
++
)
{
var
tmpAuth
=
auths
[
i
];
tmpAuth
.
app_id
=
appid
;
tmpAuth
.
company_id
=
cmid
;
var
objrtn
=
await
self
.
dao
.
model
.
findOrCreate
({
defaults
:
tmpAuth
,
where
:
{
role_id
:
tmpAuth
.
role_id
,
bizcode
:
tmpAuth
.
bizcode
},
//注意这里bizcode存储的是节点的code值
transaction
:
t
,
});
if
(
!
objrtn
[
1
].
created
)
{
//就执行更新操作
await
objrtn
[
0
].
update
(
tmpAuth
,
{
where
:
{
role_id
:
tmpAuth
.
role_id
,
bizcode
:
tmpAuth
.
bizcode
},
transaction
:
t
})
}
}
var
aths
=
await
self
.
dao
.
model
.
findAll
({
where
:
{
role_id
:
tmpAuth
.
role_id
,
app_id
:
tmpAuth
.
app_id
},
transaction
:
t
});
return
aths
;
});
}
}
module
.
exports
=
AuthService
;
module
.
exports
=
AuthService
;
center-manage/app/base/service/impl/common/channelhandlers/baidu.js
View file @
69f1a82c
...
...
@@ -170,6 +170,7 @@ class BaiduHandler {
obj
.
servicerCode
=
resInfo
.
company_id
;
}
}
catch
(
error
)
{
obj
.
salesmanOpcode
=
`root10/bizgroup01/g1members/
${
datajson
.
actionBody
.
needsolution
.
salesmanInfo
.
salesmanChannelId
}
`
;
console
.
log
(
"salesmanChannelId: "
+
datajson
.
actionBody
.
needsolution
.
salesmanInfo
.
salesmanChannelId
+
"获取业务员opcode失败:"
+
error
)
}
}
...
...
center-manage/app/base/service/impl/common/channelhandlers/zc360.js
View file @
69f1a82c
...
...
@@ -47,6 +47,7 @@ class Zc360Handler {
}
}
catch
(
error
)
{
console
.
log
(
"salesmanId: "
+
datajson
.
actionBody
.
needsolution
.
salesmanInfo
.
salesmanId
+
"获取业务员opcode失败:"
+
error
)
obj
.
salesmanOpcode
=
`root10/bizgroup01/g1members/
${
datajson
.
actionBody
.
needsolution
.
salesmanInfo
.
salesmanId
}
`
;
}
}
...
...
center-manage/app/config/routes/api.js
View file @
69f1a82c
...
...
@@ -9,79 +9,70 @@ let channelCache = {};
module
.
exports
=
function
(
app
)
{
app
.
post
(
"/autologin"
,
async
function
(
req
,
res
,
next
)
{
try
{
console
.
log
(
req
.
body
)
let
appkey
=
req
.
body
.
appkey
.
trim
()
console
.
log
(
'---- 免登 -----'
);
console
.
log
(
req
.
body
);
let
appkey
=
req
.
body
.
appkey
.
trim
();
if
(
!
appkey
)
{
let
rd
=
System
.
getResult
(
null
,
"没有资质宝appkey,请联系资质宝服务提供方"
)
res
.
end
(
JSON
.
stringify
(
rd
))
res
.
json
(
System
.
getResult
(
null
,
"没有资质宝appkey,请联系资质宝服务提供方"
));
return
}
let
companykey
=
req
.
body
.
companykey
.
trim
()
let
companykey
=
req
.
body
.
companykey
.
trim
()
;
if
(
!
companykey
)
{
let
rd
=
System
.
getResult
(
null
,
"没有公司宝的租户companykey,请联系资质宝服务提供方"
)
res
.
end
(
JSON
.
stringify
(
rd
))
res
.
json
(
System
.
getResult
(
null
,
"没有公司宝的租户companykey,请联系资质宝服务提供方"
));
return
}
//let cooktoken = req.cookies["accessToken"]
let
cooktoken
=
req
.
body
.
accesskey
console
.
log
(
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>........................................"
)
console
.
log
(
cooktoken
)
let
tv
=
cooktoken
let
sourceUser
=
System
.
verify
(
tv
,
settings
.
publickey
())
// { id: '5f8faf05787b88000a2e178b',
// name: '张华',
// employee: '5f8faf05787b88000a2e178c',
// phone: 'd1htypf8Sme3fvcXP20R+w==',
// orgid: '5bcfe95cb0a01f0009284bc3',
// roles: [ '员工', '资质宝业务员', '资质宝交付员' ],
// platform: '8cdf558c8645c7031f164dc23a55a28f',
// unionid: '',
// jti: 'gaBQQKKO6ZLNXNfA',
// exp: 1605083401,
// iat: 1604478601
// }
/**
* TODO:
* 1. 建立 磐农角色
* 2. 建立组织结构 获取 磐农组织结构路径
* 3. 获取角色id 设置
*/
let
openid
=
sourceUser
.
employee
let
userName
=
openid
let
nickName
=
sourceUser
.
name
let
unid
=
sourceUser
.
unionid
let
fixedcodes
=
[
"资质宝交付员"
,
'资质宝业务员'
]
let
rolecodes
=
sourceUser
.
roles
?
sourceUser
.
roles
:
[]
let
tv
=
cooktoken
||
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImUxNzAzYzIwMDFkZDExZTliNTBmZDUyNWJjMmE3ZTFkIn0.eyJpZCI6IjVjOTM2Yjk1ODU4MGJjNGUwOGUwODQzZSIsIm5hbWUiOiLlvKDlm73np4AiLCJlbXBsb3llZSI6IjVjOTM2YmJhYzY4ZWIxMjMwOGQxMjEzOSIsInBob25lIjoickdGR1ZwZHFiOGNPMUNYeC9VOEVYQT09Iiwib3JnaWQiOiI1YmNmZTk1Y2IwYTAxZjAwMDkyODRiYzMiLCJyb2xlcyI6WyLlkZjlt6UiLCJpZHV0eeeuoeeQhuWRmCIsIuS-m-W6lOWVhuS6pOS7mCIsIui1hOi0qOWuneS6pOS7mOWRmCJdLCJwbGF0Zm9ybSI6ImQzOTViZGFkNmI2MGY0ODQ5MTEwNDA4OWNhYjU5OGI3IiwidW5pb25pZCI6IiIsImp0aSI6Im9vMGZHR1YwZUVaOWdxbTEiLCJleHAiOjE2MDg1OTkwMjQsImlhdCI6MTYwNzk5NDIyNH0.Q3QmHoUpcX14VucsivDNHfx3DYbAI6B59i0Ohb31Vmmfw1F-kI-IV8ZTvzBi-PKY3G-ZH7FS94BHvM2KOEVKdSnTLzhd-A-LzRI6xaWFDCYdGbjMJAYtmNqzD_xZZyx4diBPHxBJLeSyb_3uMi9doMH7Ef56DgJ05UC6Ip5J1KtIRUszMNR6--PnwwsZxLeBlObaJAGkEjKBQBZUvbVlpm1yleT5t4EKcVG9EMyibYnRq2MVK273tnqb8nb2NTeyVB9nRctzSzmFwCkChYbm-z4JvSjp8PEh50FL9eVqADbpUm3lbXahYKFxmQBfxMxm8ur6fgeU7y_vRXFzL3WNFw'
let
sourceUser
=
System
.
verify
(
tv
,
settings
.
publickey
());
console
.
log
(
'--- 解析用户信息 -----'
);
console
.
log
(
sourceUser
);
let
openid
=
sourceUser
.
employee
;
let
userName
=
openid
;
let
nickName
=
sourceUser
.
name
;
let
fixedcodes
=
[
"资质宝交付员"
,
'资质宝业务员'
,
"工商业务员"
,
"工商交付员"
];
let
rolecodes
=
sourceUser
.
roles
?
sourceUser
.
roles
:
[];
let
rcs
=
rolecodes
.
filter
(
rc
=>
{
if
(
fixedcodes
.
indexOf
(
rc
)
>=
0
)
{
return
true
return
true
;
}
else
{
return
false
return
false
;
}
})
if
(
rcs
.
length
==
0
)
{
let
rd
=
System
.
getResult
(
null
,
"当前登录人没有资质宝访问权限"
)
res
.
end
(
JSON
.
stringify
(
rd
))
});
if
(
rcs
.
length
===
0
)
{
res
.
json
(
System
.
getResult
(
null
,
"当前登录人没有资质宝访问权限"
));
return
}
//先按照openid去查看是否已经存在
let
uf
=
await
userS
.
dao
.
model
.
findOne
({
where
:
{
openid
:
openid
}
})
//先按照openid去查看是否已经存在
let
uf
=
await
userS
.
dao
.
model
.
findOne
({
where
:
{
openid
:
openid
}
})
;
if
(
!
uf
)
{
//按照公司companykey查询出要注册公司的所在公司,取公司id
let
company
=
await
companyS
.
dao
.
model
.
findOne
({
where
:
{
companykey
:
companykey
}
})
let
company
=
await
companyS
.
dao
.
model
.
findOne
({
where
:
{
companykey
:
companykey
}
})
;
//构造注册用户对象,需要设置默认角色,默认角色需要按照rolecode查询出角色
let
rolesfind
=
await
roleS
.
dao
.
model
.
findAll
({
where
:
{
code
:
{
[
roleS
.
db
.
Op
.
in
]:
rcs
},
company_id
:
company
.
id
}
})
let
rolesfind
=
await
roleS
.
dao
.
model
.
findAll
({
where
:
{
code
:
{
[
roleS
.
db
.
Op
.
in
]:
rcs
},
company_id
:
company
.
id
}
})
;
//根据rolecode--,设置组织路径
let
opath
=
''
let
isSalesman
=
false
let
isDelivery
=
false
if
(
rcs
[
0
]
==
"资质宝业务员"
)
{
opath
=
"root10/bizgroup01/g1members/"
+
userName
isSalesman
=
true
}
else
{
opath
=
"root10/dlivergroup/dgroupmembers/"
+
userName
isDelivery
=
true
let
opath
=
''
;
let
isSalesman
=
false
;
let
isDelivery
=
false
;
let
skilltags
=
new
Set
();
if
(
rcs
.
includes
(
"资质宝交付员"
))
{
isDelivery
=
true
;
opath
=
"root10/dlivergroup/dgroupmembers/"
+
userName
;
skilltags
.
add
(
"icp,edi"
);
}
if
(
rcs
.
includes
(
"工商交付员"
))
{
isDelivery
=
true
;
opath
=
"root10/dlivergroup/dgroupmembers/"
+
userName
;
skilltags
.
add
(
"公司注册"
);
}
if
(
rcs
.
includes
(
"资质宝业务员"
))
{
isSalesman
=
true
;
opath
=
"root10/bizgroup01/g1members/"
+
userName
;
skilltags
.
add
(
"icp,edi"
);
}
if
(
rcs
.
includes
(
"工商业务员"
))
{
isSalesman
=
true
;
opath
=
"root10/bizgroup01/g1members/"
+
userName
;
skilltags
.
add
(
"公司注册"
);
}
//调用pmregister
let
reguser
=
{
...
...
@@ -94,16 +85,14 @@ module.exports = function (app) {
isSalesman
:
isSalesman
,
isDelivery
:
isDelivery
,
isAllocated
:
true
,
skilltags
:
'icp,edi'
skilltags
:
[...
skilltags
].
join
()
}
uf
=
await
userS
.
registerByTantent
(
reguser
)
}
let
rtnobj
=
await
userS
.
loginApp
(
appkey
,
userName
)
let
rtntmp
=
System
.
getResult
({
openurl
:
rtnobj
.
homePage
+
"?code="
+
rtnobj
.
code
})
let
rtn
=
JSON
.
stringify
(
rtntmp
)
res
.
end
(
rtn
)
let
rtnobj
=
await
userS
.
loginApp
(
appkey
,
userName
);
res
.
json
(
System
.
getResult
({
openurl
:
rtnobj
.
homePage
+
"?code="
+
rtnobj
.
code
}))
}
catch
(
e
)
{
res
.
end
(
JSON
.
stringify
(
System
.
getResult
(
null
,
e
.
message
)))
res
.
json
(
System
.
getResult
(
null
,
e
.
message
));
}
})
app
.
post
(
"/entService/*"
,
async
function
(
req
,
res
,
next
)
{
...
...
@@ -151,7 +140,7 @@ module.exports = function (app) {
}
}
catch
(
e
)
{
console
.
log
(
e
)
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
e
})
);
res
.
json
({
status
:
-
1
,
message
:
e
}
);
}
})
app
.
get
(
'/api/:gname/:qname/:method'
,
function
(
req
,
res
)
{
...
...
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