1
|
'use strict';
|
1
|
'use strict';
|
2
|
|
2
|
|
3
|
-const _ = require('lodash');
|
|
|
4
|
const Fp = require('lodash/fp');
|
3
|
const Fp = require('lodash/fp');
|
5
|
const cookie = global.yoho.cookie;
|
4
|
const cookie = global.yoho.cookie;
|
6
|
|
5
|
|
7
|
module.exports = () => {
|
6
|
module.exports = () => {
|
8
|
return (req, res, next) => {
|
7
|
return (req, res, next) => {
|
9
|
- // 从 SESSION 中获取到当前登录用户的 UID
|
|
|
10
|
- if (req.session && _.isNumber(req.session._LOGIN_UID)) {
|
|
|
11
|
- req.user.uid = req.session._LOGIN_UID;
|
|
|
12
|
- }
|
|
|
13
|
|
8
|
|
14
|
// session 没有读取到的时候,从 cookie 读取 UID
|
9
|
// session 没有读取到的时候,从 cookie 读取 UID
|
15
|
- if (!req.user.uid && req.cookies._UID) {
|
10
|
+ if (req.cookies._UID) {
|
16
|
req.user.uid = cookie.getUid(req);
|
11
|
req.user.uid = cookie.getUid(req);
|
17
|
- }
|
|
|
18
|
|
12
|
|
19
|
- // 获得vip 信息
|
|
|
20
|
- if (req.user.uid && req.cookies._UID) {
|
|
|
21
|
let getVip = Fp.pipe(Fp.split('::'), Fp.nth(2));
|
13
|
let getVip = Fp.pipe(Fp.split('::'), Fp.nth(2));
|
22
|
|
14
|
|
23
|
req.user.vip = getVip(req.cookies._UID);
|
15
|
req.user.vip = getVip(req.cookies._UID);
|
24
|
}
|
16
|
}
|
25
|
|
17
|
|
|
|
18
|
+ // 从 SESSION 中获取到当前登录用户的 UID
|
|
|
19
|
+ // if (req.session && _.isNumber(req.session._LOGIN_UID)) {
|
|
|
20
|
+ // req.user.uid = req.session._LOGIN_UID;
|
|
|
21
|
+ // }
|
|
|
22
|
+
|
26
|
next();
|
23
|
next();
|
27
|
};
|
24
|
};
|
28
|
}; |
25
|
}; |