user.js
698 Bytes
'use strict';
const Fp = require('lodash/fp');
const cookie = global.yoho.cookie;
module.exports = () => {
return (req, res, next) => {
// 从 cookie 读取 UID
if (req.cookies._UID) {
let uidCookie = req.cookies._UID.split('::');
let getName = Fp.nth(0);
let getVip = Fp.nth(2);
let getToken = Fp.nth(3);
req.user.name = getName(uidCookie); //0
req.user.uid = cookie.getUid(req); //1
req.user.vip = getVip(uidCookie); //2
req.user.token = getToken(uidCookie); //3
req.user.isStudent = req.cookies.isStudent || 0;
}
next();
};
};