user.js 789 Bytes
'use strict';

const Fp = require('lodash/fp');
const cookie = global.yoho.cookie;

module.exports = () => {
    return (req, res, next) => {

        // session 没有读取到的时候,从 cookie 读取 UID
        if (req.cookies._UID) {
            req.user.uid = cookie.getUid(req);

            let getVip = Fp.pipe(Fp.split('::'), Fp.nth(2));

            req.user.vip = getVip(req.cookies._UID);
        }

        // 用户是否学生
        if (req.user.uid && req.cookies.isStudent) {
            req.user.isStudent = req.cookies.isStudent;
        }

        // 从 SESSION 中获取到当前登录用户的 UID
        // if (req.session && _.isNumber(req.session._LOGIN_UID)) {
        //    req.user.uid = req.session._LOGIN_UID;
        // }

        next();
    };
};