Authored by ccbikai

add uid check

... ... @@ -11,7 +11,7 @@ module.exports = (req, res, next) => {
if (!req.user.uid) {
if (req.xhr) {
return res.json({
code: 400,
code: 401,
message: '抱歉,您暂未登录!'
});
}
... ...
const _ = require('lodash');
const cookie = global.yoho.cookie;
const md5 = require('yoho-md5');
module.exports = () => {
return (req, res, next) => {
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session._LOGIN_UID)) {
req.user.uid = req.session._LOGIN_UID;
}
const uid = req.cookies._YOHOUID;
const token = req.cookies._YOHOTOKEN;
const key = `-_-!!!${uid}!!!-_-`;
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
req.user.uid = cookie.getUid(req);
if (md5(key) === token) {
req.user.uid = uid;
}
next();
... ...
... ... @@ -29,7 +29,6 @@
"express-session": "^1.14.0",
"influxdb-winston": "^1.0.1",
"lodash": "^4.13.1",
"md5": "^2.1.0",
"memcached": "^2.2.1",
"moment": "^2.14.1",
"morgan": "^1.7.0",
... ... @@ -39,6 +38,7 @@
"uuid": "^2.0.2",
"winston": "^2.2.0",
"winston-daily-rotate-file": "^1.1.4",
"yoho-md5": "^2.0.0",
"yoho-node-lib": "0.0.21"
},
"devDependencies": {
... ...