|
@@ -3,29 +3,29 @@ |
|
@@ -3,29 +3,29 @@ |
3
|
const _ = require('lodash');
|
3
|
const _ = require('lodash');
|
4
|
const cookie = global.yoho.cookie;
|
4
|
const cookie = global.yoho.cookie;
|
5
|
const crypto = global.yoho.crypto;
|
5
|
const crypto = global.yoho.crypto;
|
|
|
6
|
+const authcode = require('../../utils/authcode');
|
6
|
|
7
|
|
7
|
module.exports = () => {
|
8
|
module.exports = () => {
|
8
|
return (req, res, next) => {
|
9
|
return (req, res, next) => {
|
9
|
// 从 SESSION 中获取到当前登录用户的 UID
|
10
|
// 从 SESSION 中获取到当前登录用户的 UID
|
10
|
- if (req.session && _.isNumber(req.session.LOGIN_UID)) {
|
|
|
11
|
- // 不要使用 === 判断uid的值,如果需要判断使用 ==
|
|
|
12
|
- req.user.uid = {
|
|
|
13
|
- toString: () => {
|
|
|
14
|
- return req.session.LOGIN_UID;
|
|
|
15
|
- },
|
|
|
16
|
- sessionKey: req.session.SESSION_KEY
|
|
|
17
|
- };
|
|
|
18
|
- let userData = _.get(req.session, 'USER', {});
|
11
|
+ // if (req.session && _.isNumber(req.session.LOGIN_UID)) {
|
|
|
12
|
+ // // 不要使用 === 判断uid的值,如果需要判断使用 ==
|
|
|
13
|
+ // req.user.uid = {
|
|
|
14
|
+ // toString: () => {
|
|
|
15
|
+ // return req.session.LOGIN_UID;
|
|
|
16
|
+ // },
|
|
|
17
|
+ // sessionKey: req.session.SESSION_KEY
|
|
|
18
|
+ // };
|
|
|
19
|
+ // let userData = _.get(req.session, 'USER', {});
|
19
|
|
20
|
|
20
|
- _.merge(req.user, userData);
|
|
|
21
|
- }
|
21
|
+ // _.merge(req.user, userData);
|
|
|
22
|
+ // }
|
22
|
|
23
|
|
23
|
// session 没有读取到的时候,从 cookie 读取 UID
|
24
|
// session 没有读取到的时候,从 cookie 读取 UID
|
24
|
if (!req.user.uid && req.cookies._UID) {
|
25
|
if (!req.user.uid && req.cookies._UID) {
|
25
|
// 不要使用 === 判断uid的值,如果需要判断使用 ==
|
26
|
// 不要使用 === 判断uid的值,如果需要判断使用 ==
|
26
|
- let sessionKey = req.cookies._SESSION_KEY && crypto.decrypt('yoho9646abcdefgh', req.cookies._SESSION_KEY);
|
27
|
+ let sessionKey = req.cookies._SESSION_KEY && authcode(req.cookies._SESSION_KEY, '_SESSION_KEY', 2592000000);
|
27
|
|
28
|
|
28
|
- sessionKey = sessionKey.replace(/[^\w:-]/g, '');
|
|
|
29
|
req.user.uid = {
|
29
|
req.user.uid = {
|
30
|
toString: () => {
|
30
|
toString: () => {
|
31
|
return cookie.getUid(req);
|
31
|
return cookie.getUid(req);
|