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
937a2439
Commit
937a2439
authored
Nov 18, 2019
by
王昆
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gsb
parent
2566a7fc
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
79 additions
and
75 deletions
+79
-75
xgg-admin/app/base/controller/ctl.base.js
+2
-2
xgg-admin/app/base/controller/impl/auth/userCtl.js
+9
-53
xgg-admin/app/base/controller/impl/common/captchaCtl.js
+0
-1
xgg-admin/app/base/service/impl/auth/userSve.js
+23
-4
xgg-admin/app/base/system.js
+4
-4
xgg-admin/app/base/utils/businessManager/opPlatformUtils.js
+18
-2
xgg-admin/app/config/routes/api.js
+8
-2
xgg-admin/app/config/routes/web.js
+6
-6
xgg-admin/app/config/settings.js
+9
-1
No files found.
xgg-admin/app/base/controller/ctl.base.js
View file @
937a2439
...
...
@@ -104,9 +104,9 @@ class CtlBase {
var
d
=
new
Date
(
time
);
return
d
.
getFullYear
()
+
'-'
+
(
d
.
getMonth
()
+
1
)
+
'-'
+
d
.
getDate
();
}
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
async
doexec
(
methodname
,
pobj
,
query
,
req
,
res
)
{
try
{
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
,
res
);
return
rtn
;
}
catch
(
e
)
{
console
.
log
(
e
.
stack
);
...
...
xgg-admin/app/base/controller/impl/auth/userCtl.js
View file @
937a2439
...
...
@@ -46,50 +46,24 @@ class UserCtl extends CtlBase {
if
(
vrs
.
status
!==
0
)
{
// return vrs;
}
// 查用户
var
loginrs
=
await
this
.
platformUtils
.
login
(
loginName
,
password
);
if
(
loginrs
.
status
!==
0
)
{
return
loginrs
;
}
var
puser
=
loginrs
.
Data
;
return
system
.
getResultSuccess
(
puser
);
// this.service.getUserByUserNamePwd({
// userName: loginName,
// password: password,
// app_id: settings.app_id
// });
// var adminUser = await this.service.findOne({
// ucname: loginName
// });
// // var adminUser = await this.service.findById(1);
// if (!adminUser) {
// return system.getResult(null, "用户名或密码错误");
// }
// var passwdMD5 = md5(password);
// if (passwdMD5 != adminUser.passwd) {
// return system.getResult(null, "用户名或密码错误");
// }
// adminUser.lastLoginTime = new Date();
// await adminUser.save();
// var xggadminsid = uuidv4();
// xggadminsid = "3cb49932-fa02-44f0-90db-9f06fe02e5c7";
// await this.redisClient.setWithEx(xggadminsid, JSON.stringify(adminUser), 60 * 60 * 2);
// // 处理登录逻辑
// var result = {
// xggadminsid: xggadminsid,
// }
// return system.getResultSuccess(result);
var
user
=
await
this
.
service
.
authByCode
(
loginrs
.
data
.
opencode
);
req
.
session
.
user
=
user
;
return
system
.
getResultSuccess
(
user
);
}
catch
(
error
)
{
return
system
.
getResultFail
(
500
,
"接口异常:"
+
error
.
message
);
}
}
async
setLogin
(
req
,
res
,
user
)
{
var
xggadminsid
=
uuidv4
();
await
this
.
redisClient
.
setWithEx
(
xggadminsid
+
"_admin_user"
,
JSON
.
stringify
(
user
),
60
*
60
*
2
);
return
xggadminsid
;
}
async
forgetPassword
(
qobj
,
pobj
,
req
,
res
)
{
var
mobile
=
this
.
trim
(
pobj
.
mobile
);
...
...
@@ -279,27 +253,9 @@ class UserCtl extends CtlBase {
async
checkLogin
(
gobj
,
qobj
,
req
)
{
//当前如果缓存中存在user,还是要检查当前user所在的域名,如果不和来访一致,则退出重新登录
if
(
req
.
session
.
user
)
{
var
x
=
null
;
if
(
req
.
session
.
user
.
Roles
)
{
x
=
req
.
session
.
user
.
Roles
.
map
(
r
=>
{
return
r
.
code
});
}
var
tmp
=
{
id
:
req
.
session
.
user
.
id
,
userName
:
req
.
session
.
user
.
userName
,
nickName
:
req
.
session
.
user
.
nickName
,
mobile
:
req
.
session
.
user
.
mobile
,
isAdmin
:
req
.
session
.
user
.
isAdmin
,
created_at
:
req
.
session
.
user
.
created_at
,
email
:
req
.
session
.
user
.
email
,
headUrl
:
req
.
session
.
user
.
headUrl
,
roles
:
x
?
x
.
join
(
","
)
:
""
}
return
system
.
getResult
(
tmp
,
"用户登录"
,
req
);
return
system
.
getResultSuccess
(
req
.
session
.
user
);
}
else
{
req
.
session
.
user
=
null
;
//req.session.destroy();
return
system
.
getResult
(
null
,
"用户未登录"
,
req
);
}
}
...
...
xgg-admin/app/base/controller/impl/common/captchaCtl.js
View file @
937a2439
...
...
@@ -3,7 +3,6 @@ var settings = require("../../../../config/settings");
const
CtlBase
=
require
(
"../../ctlms.base"
);
const
uuidv4
=
require
(
'uuid/v4'
);
var
moment
=
require
(
"moment"
);
var
svgCaptcha
=
require
(
'svg-captcha'
);
class
CaptchaCtl
extends
CtlBase
{
constructor
()
{
...
...
xgg-admin/app/base/service/impl/auth/userSve.js
View file @
937a2439
...
...
@@ -4,18 +4,37 @@ const settings = require("../../../../config/settings")
class
UserService
extends
ServiceBase
{
constructor
()
{
super
(
"auth"
,
ServiceBase
.
getDaoName
(
UserService
));
this
.
platformUtils
=
system
.
getObject
(
"util.businessManager.opPlatformUtils"
);
}
async
saveUser
(
user
)
{
var
u
=
await
this
.
dao
.
findOne
({
ucid
:
user
.
ucid
,
})
||
{};
u
.
ucid
=
user
.
ucid
;
u
.
ucname
=
user
.
ucname
;
u
.
passwd
=
user
.
passwd
;
u
.
lastLoginTime
=
user
.
lastLoginTime
;
if
(
u
.
id
)
{
u
=
await
this
.
dao
.
create
(
ucid
);
}
else
{
await
u
.
save
();
}
return
u
;
}
async
authByCode
(
opencode
)
{
var
existedUser
=
null
;
var
rawUser
=
null
;
var
openuser
=
await
this
.
apiCallWithAk
(
settings
.
paasUrl
()
+
"api/auth/accessAuth/authByCode"
,
{
opencode
:
opencode
});
if
(
openuser
)
{
//先查看自己系统中是否已经存在当前用户
existedUser
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
ucname
:
openuser
.
userName
,
ucid
:
openuser
.
id
},
raw
:
true
});
existedUser
=
await
this
.
dao
.
model
.
findOne
({
where
:
{
ucname
:
openuser
.
userName
,
ucid
:
openuser
.
account_
id
},
raw
:
true
});
if
(
!
existedUser
)
{
existedUser
=
await
this
.
register
(
openuser
);
}
rawUser
=
existedUser
.
get
({
raw
:
true
})
;
rawUser
=
existedUser
;
rawUser
.
Roles
=
openuser
.
Roles
;
}
return
rawUser
;
...
...
@@ -25,8 +44,8 @@ class UserService extends ServiceBase {
}
async
register
(
openuser
)
{
var
param
=
{
ucname
:
openuser
.
userName
,
ucid
:
openuser
.
id
,
last
_login_t
ime
:
new
Date
()
ucname
:
openuser
.
userName
,
ucid
:
openuser
.
account_
id
,
last
LoginT
ime
:
new
Date
()
}
var
cruser
=
await
this
.
dao
.
create
(
param
);
return
cruser
;
...
...
xgg-admin/app/base/system.js
View file @
937a2439
...
...
@@ -173,8 +173,8 @@ class System {
// var domain = "http://127.0.0.1";
return
{
// 公共服务
//
common: domain + ":3102" + path,
common
:
"http://127.0.0.1:3102"
+
path
,
common
:
domain
+
":3102"
+
path
,
//
common: "http://127.0.0.1:3102" + path,
// 商户服务
merchant
:
domain
+
":3101"
+
path
,
...
...
@@ -185,8 +185,8 @@ class System {
// order: "http://127.0.0.1:3103" + path,
// 发票服务
//
invoice: domain + ":3105" + path,
invoice
:
"http://127.0.0.1:3105"
+
path
,
invoice
:
domain
+
":3105"
+
path
,
//
invoice: "http://127.0.0.1:3105" + path,
}
}
else
{
var
odomain
=
"http://123.57.217.203"
...
...
xgg-admin/app/base/utils/businessManager/opPlatformUtils.js
View file @
937a2439
...
...
@@ -67,7 +67,9 @@ class OpPlatformUtils {
if
(
!
reqApiAccessKey
||
!
reqApiAccessKey
.
accessKey
)
{
return
system
.
getResult
(
null
,
"获取请求token失败"
);
}
var
param
=
{
mobile
:
mobile
}
var
param
=
{
mobile
:
mobile
}
//按照访问token
var
restResult
=
await
this
.
restClient
.
execPostWithAK
(
param
,
...
...
@@ -144,6 +146,19 @@ class OpPlatformUtils {
}
return
system
.
getResultSuccess
(
restResult
.
data
);
}
/**
* 登录并获取登录用户信息
* @param {*} userName
* @param {*} password
*/
async
loginInfo
(
userName
,
password
)
{
var
loginrs
=
await
this
.
login
(
userName
,
password
);
if
(
loginrs
.
status
!==
0
)
{
return
loginrs
;
}
return
await
this
.
authByCode
(
loginrs
.
data
.
opencode
)
}
}
module
.
exports
=
OpPlatformUtils
;
module
.
exports
=
OpPlatformUtils
;
\ No newline at end of file
xgg-admin/app/config/routes/api.js
View file @
937a2439
var
url
=
require
(
"url"
);
var
system
=
require
(
"../../base/system"
);
var
settings
=
require
(
"../settings"
);
var
userSve
=
system
.
getObject
(
"service.auth.userSve"
);
module
.
exports
=
function
(
app
)
{
app
.
get
(
"/auth"
,
async
function
(
req
,
res
)
{
if
(
!
req
.
query
.
opencode
)
{
var
opencode
=
req
.
query
.
opencode
||
""
;
if
(
!
opencode
)
{
return
system
.
getResult
(
null
,
"opencode参数不能为空"
);
}
return
await
userSve
.
authByCode
(
opencode
);
var
user
=
await
userSve
.
authByCode
(
opencode
);
req
.
session
.
user
=
user
;
console
.
log
(
req
.
session
.
id
);
res
.
redirect
(
settings
.
indexPage
());
});
app
.
get
(
'/api/:gname/:qname/:method'
,
function
(
req
,
res
)
{
var
classPath
=
req
.
params
[
"qname"
];
...
...
xgg-admin/app/config/routes/web.js
View file @
937a2439
...
...
@@ -7,8 +7,9 @@ const redisClient = system.getObject("util.redisClient");
module
.
exports
=
function
(
app
)
{
app
.
all
(
"/web/*"
,
async
function
(
req
,
res
,
next
)
{
var
xggadminsid
=
req
.
headers
[
"xggadminsid"
]
||
""
;
var
jsonUser
=
await
redisClient
.
get
(
xggadminsid
);
// var xggadminsid = req.headers["xggadminsid"] || "";
// var jsonUser = await redisClient.get(xggadminsid);
var
jsonUser
=
req
.
session
.
user
;
if
(
req
.
url
.
indexOf
(
"auth/userCtl/login"
)
>
0
||
req
.
url
.
indexOf
(
"auth/userCtl/smsCode"
)
>
0
||
...
...
@@ -17,7 +18,7 @@ module.exports = function (app) {
req
.
url
.
indexOf
(
"getRsConfig"
)
>
0
)
{
if
(
jsonUser
)
{
req
.
loginUser
=
JSON
.
parse
(
jsonUser
)
;
req
.
loginUser
=
jsonUser
;
}
else
{
req
.
loginUser
=
null
;
}
...
...
@@ -27,10 +28,9 @@ module.exports = function (app) {
if
(
!
jsonUser
)
{
res
.
end
(
JSON
.
stringify
({
status
:
-
99
,
msg
:
"no login"
}));
return
;
}
else
{
redisClient
.
setWithEx
(
xggadminsid
,
jsonUser
,
60
*
60
*
3
);
}
req
.
loginUser
=
JSON
.
parse
(
jsonUser
);
req
.
session
.
user
=
jsonUser
;
req
.
loginUser
=
jsonUser
;
next
();
});
...
...
xgg-admin/app/config/settings.js
View file @
937a2439
...
...
@@ -35,7 +35,7 @@ var settings = {
},
paasUrl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
return
"http://
open.gongsibao.com
/"
;
return
"http://
192.168.18.125:4001
/"
;
}
else
{
return
"http://open.gongsibao.com/"
;
}
...
...
@@ -48,6 +48,14 @@ var settings = {
return
1
;
},
},
indexPage
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
// return "http://localhost:8080";
return
"https://xggadmin.gongsibao.com"
;
}
else
{
return
"https://xggadmin.gongsibao.com"
;
}
},
homePage
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
var
localsettings
=
require
(
"./localsettings"
);
...
...
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