Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-blk
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
1
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
htoooth
9 years ago
Commit
7f6a6e9c1cadbf3fc3d2a3bfee99875d205271c5
1 parent
f70e1df5
修复登录后,购物消失的问题
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
7 deletions
apps/passport/models/login-service.js
doraemon/middleware/auth.js
doraemon/middleware/user.js
apps/passport/models/login-service.js
View file @
7f6a6e9
...
...
@@ -9,6 +9,7 @@ const _ = require('lodash');
const
cache
=
global
.
yoho
.
cache
;
const
sign
=
global
.
yoho
.
sign
;
const
config
=
global
.
yoho
.
config
;
const
crypto
=
global
.
yoho
.
crypto
;
const
api
=
require
(
'./login-api'
);
const
UserService
=
require
(
'./user-service'
);
...
...
@@ -37,7 +38,7 @@ const syncUserSession = (uid, req, res) => {
let
user
=
userInfo
.
data
;
if
(
!
_
.
isEmpty
(
user
))
{
let
uidCookie
=
`
{
data
.
profile_name
}::
$
{
user
.
uid
}::
$
{
user
.
username
}
::
$
{
token
}
`
;
let
uidCookie
=
`
$
{
user
.
profile_name
}::
$
{
crypto
.
encryption
(
''
,
user
.
uid
+
''
)
}::
$
{
user
.
username
}
::
$
{
token
}
`
;
req
.
session
.
_TOKEN
=
token
;
req
.
session
.
_LOGIN_UID
=
uid
;
...
...
doraemon/middleware/auth.js
View file @
7f6a6e9
...
...
@@ -13,8 +13,6 @@ module.exports = (req, res, next) => {
let
refer
=
''
;
if
(
req
.
method
===
'GET'
)
{
refer
=
req
.
getUrl
();
}
else
{
refer
=
req
.
get
(
'Referer'
);
}
...
...
doraemon/middleware/user.js
View file @
7f6a6e9
...
...
@@ -10,9 +10,6 @@ const LoginService = require('../../apps/passport/models/login-service');
*/
module
.
exports
=
()
=>
{
return
(
req
,
res
,
next
)
=>
{
req
.
getUrl
=
function
()
{
return
req
.
protocol
+
'://'
+
req
.
get
(
'host'
)
+
req
.
originalUrl
;
};
// 从 SESSION 中获取到当前登录用户的 UID
if
(
req
.
session
&&
_
.
isNumber
(
req
.
session
.
_LOGIN_UID
))
{
...
...
@@ -22,6 +19,7 @@ module.exports = () => {
// session 没有读取到的时候,从 cookie 读取 UID
if
(
!
req
.
user
.
uid
&&
req
.
cookies
.
_UID
)
{
req
.
user
.
uid
=
cookie
.
getUid
(
req
);
console
.
log
(
'req.user.uid'
,
req
.
user
.
uid
);
}
// 从 SESSION 中获得 USERNAME
...
...
@@ -49,7 +47,7 @@ module.exports = () => {
return
LoginService
.
syncUserSession
(
result
.
data
.
uid
,
req
,
res
);
}).
then
(()
=>
{
return
res
.
redirect
(
req
.
getUrl
()
);
return
res
.
redirect
(
req
.
originalUrl
);
}).
catch
(
next
);
}
else
{
return
next
();
...
...
Please
register
or
login
to post a comment