Authored by htoooth

修复登录后,购物消失的问题

... ... @@ -9,6 +9,7 @@ const _ = require('lodash');
const cache = global.yoho.cache;
const sign = global.yoho.sign;
const config = global.yoho.config;
const crypto = global.yoho.crypto;
const api = require('./login-api');
const UserService = require('./user-service');
... ... @@ -37,7 +38,7 @@ const syncUserSession = (uid, req, res) => {
let user = userInfo.data;
if (!_.isEmpty(user)) {
let uidCookie = `{data.profile_name}::${user.uid}::${user.username}::${token}`;
let uidCookie = `${user.profile_name}::${crypto.encryption('', user.uid + '')}::${user.username}::${token}`;
req.session._TOKEN = token;
req.session._LOGIN_UID = uid;
... ...
... ... @@ -13,8 +13,6 @@ module.exports = (req, res, next) => {
let refer = '';
if (req.method === 'GET') {
refer = req.getUrl();
} else {
refer = req.get('Referer');
}
... ...
... ... @@ -10,9 +10,6 @@ const LoginService = require('../../apps/passport/models/login-service');
*/
module.exports = () => {
return (req, res, next) => {
req.getUrl = function() {
return req.protocol + '://' + req.get('host') + req.originalUrl;
};
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session._LOGIN_UID)) {
... ... @@ -22,6 +19,7 @@ module.exports = () => {
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
req.user.uid = cookie.getUid(req);
console.log('req.user.uid', req.user.uid);
}
// 从 SESSION 中获得 USERNAME
... ... @@ -49,7 +47,7 @@ module.exports = () => {
return LoginService.syncUserSession(result.data.uid, req, res);
}).then(()=> {
return res.redirect(req.getUrl());
return res.redirect(req.originalUrl);
}).catch(next);
} else {
return next();
... ...