Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
htoooth
8 years ago
Commit
f1eb77b0ec99ed365cc821262d491db1d4aece57
1 parent
f102afaa
fix lib
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
4 deletions
apps/passport/models/login-service.js
doraemon/middleware/user.js
package.json
apps/passport/models/login-service.js
View file @
f1eb77b
...
...
@@ -10,6 +10,8 @@ const sign = global.yoho.sign;
const
cookie
=
global
.
yoho
.
cookie
;
const
config
=
global
.
yoho
.
config
;
const
crypto
=
global
.
yoho
.
crypto
;
const
authcode
=
require
(
`
$
{
global
.
utils
}
/authcode`
)
;
const
AUTH_TIME
=
2592000000
;
const
Promise
=
require
(
'bluebird'
);
...
...
@@ -60,7 +62,7 @@ const syncUserSession = (uid, req, res, sessionKey) => {
res
.
cookie
(
'isStudent'
,
isStudent
,
{
domain
:
config
.
cookieDomain
});
res
.
cookie
(
'_SESSION
'
,
sessionKey
,
{
res
.
cookie
(
'_SESSION
_KEY'
,
authcode
(
sessionKey
,
'_SESSION_KEY'
,
AUTH_TIME
,
'encode'
)
,
{
domain
:
config
.
cookieDomain
});
...
...
doraemon/middleware/user.js
View file @
f1eb77b
...
...
@@ -2,11 +2,16 @@
const
Fn
=
require
(
'lodash/fp'
);
const
cookie
=
global
.
yoho
.
cookie
;
const
authcode
=
require
(
`
$
{
global
.
utils
}
/authcode`
)
;
// const loginService = require('../../apps/passport/models/login-service');
// const _ = require('lodash');
// const cache = global.yoho.cache;
function
decrypt
(
word
)
{
return
authcode
(
word
,
'_SESSION_KEY'
);
}
module
.
exports
=
()
=>
{
return
(
req
,
res
,
next
)
=>
{
...
...
@@ -14,7 +19,7 @@ module.exports = () => {
req
.
fullUrl
=
()
=>
req
.
protocol
+
'://'
+
req
.
get
(
'host'
)
+
req
.
originalUrl
;
// 从 cookie 读取 UID
if
(
req
.
cookies
.
_UID
&&
req
.
cookies
.
_SESSION
)
{
if
(
req
.
cookies
.
_UID
&&
req
.
cookies
.
_SESSION
_KEY
)
{
let
uidCookie
=
req
.
cookies
.
_UID
.
split
(
'::'
);
...
...
@@ -26,12 +31,13 @@ module.exports = () => {
req
.
user
.
vip
=
getVip
(
uidCookie
);
// 2
req
.
user
.
token
=
getToken
(
uidCookie
);
// 3
req
.
user
.
isStudent
=
req
.
cookies
.
isStudent
||
0
;
req
.
user
.
uid
=
{
toString
()
{
return
this
.
uid
;
},
uid
:
cookie
.
getUid
(
req
),
sessionKey
:
req
.
cookies
.
_SESSION
,
sessionKey
:
decrypt
(
req
.
cookies
.
_SESSION_KEY
)
,
isValid
()
{
return
this
.
uid
&&
this
.
sessionKey
;
}
...
...
package.json
View file @
f1eb77b
...
...
@@ -64,7 +64,7 @@
"urlencode"
:
"^1.1.0"
,
"uuid"
:
"^2.0.2"
,
"yoho-express-session"
:
"^2.0.0"
,
"yoho-node-lib"
:
"0.2.
8
"
,
"yoho-node-lib"
:
"0.2.
10
"
,
"yoho-zookeeper"
:
"^1.0.8"
},
"devDependencies"
:
{
...
...
Please
register
or
login
to post a comment