Authored by htoooth

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

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