Authored by ccbikai(👎🏻🍜)

reset

... ... @@ -24,10 +24,10 @@ const favicon = require('serve-favicon');
const uuid = require('uuid');
const pkg = require('./package.json');
const CookieSession = require('client-sessions');
const MemcachedSession = require('yoho-express-session');
const cookieSession = require('client-sessions');
const memcachedSession = require('yoho-express-session');
const memcached = require('connect-memcached');
const MemcachedStore = memcached(MemcachedSession);
const MemcachedStore = memcached(memcachedSession);
const _ = require('lodash');
const app = express();
... ... @@ -76,7 +76,7 @@ app.use(bodyParser.urlencoded({
app.use(cookieParser());
app.use(compression());
app.use(MemcachedSession({
app.use(memcachedSession({
proxy: true,
resave: false,
saveUninitialized: true,
... ... @@ -87,9 +87,6 @@ app.use(MemcachedSession({
domain: 'yohobuy.com',
httpOnly: false
},
// genid() {
// return uuid.v4() // use UUIDs for session IDs
// },
store: new MemcachedStore({
hosts: config.memcache.session,
prefix: 'yohobuy_session:',
... ... @@ -99,52 +96,43 @@ app.use(MemcachedSession({
})
}));
// app.use(CookieSession({
// requestKey: 'session2',
// cookieName: 'yohobuy_session_cookie',
// secret: '82dd7e724f2c6870472c89dfa43cf48d',
// domain: config.cookieDomain
// }));
// app.use((req, res, next) => {
// if (req.session) {
// let sessionKeys = Object.keys(req.session || {});
// let backSessionKeys = Object.keys(req.session2.sessionBack || {});
// if (backSessionKeys.length > sessionKeys.length) {
// let differences = _.difference(backSessionKeys, sessionKeys);
// _.forEach(differences, d => {
// req.session[d] = req.session2.sessionBack[d];
// });
// }
// req.session2.sessionBack = req.session;
// } else {
// req.session = new MemcachedSession.Session(req);
// req.session = _.assign(req.session, req.session2.sessionBack);
// }
// if (typeof req.session.reset !== 'function') {
// req.session.reset = function() {
// req.session.destroy();
// req.session2.reset();
// };
// }
// next();
// });
app.use(cookieSession({
requestKey: 'session2',
cookieName: 'yohobuy_session_cookie',
secret: '82dd7e724f2c6870472c89dfa43cf48d',
domain: config.cookieDomain
}));
app.use((req, res, next) => {
if (req.session) {
let sessionKeys = Object.keys(req.session || {});
let backSessionKeys = Object.keys(req.session2.sessionBack || {});
if (backSessionKeys.length > sessionKeys.length) {
let differences = _.difference(backSessionKeys, sessionKeys);
_.forEach(differences, d => {
req.session[d] = req.session2.sessionBack[d];
});
}
req.session2.sessionBack = req.session;
} else {
req.session = new memcachedSession.Session(req);
req.session = _.assign(req.session, req.session2.sessionBack);
}
if (!req.sessionID) {
req.sessionID = uuid.v4();
}
next();
});
app.use((req, res, next) => {
req.user = {}; // 全局的用户数据
req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
req.app.locals.wap = app.locals.wap; // zookeper对象赋值
if (!req.session) {
req.session = {};
}
if (!req.session.id) {
req.session.id = uuid.v4();
}
req.sessionID = req.session.id;
next();
});
... ...
... ... @@ -143,6 +143,7 @@ const local = {
res.render('international', {
width750: true,
// 返回的URL链接
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
loginInternational: true, // 模板中使用JS的标识
... ... @@ -179,6 +180,7 @@ const local = {
if (!errorCount) {
_.set(req.session, 'captchaValidCount', 5);
// delete req.session.captcha; // 验证码 用过就扔
req.session.captcha = null;
jsonData.changeCaptcha = true;
... ... @@ -235,7 +237,12 @@ const local = {
})(req, res, next);
},
logout: (req, res) => {
req.session.destroy();
if (req.session && req.session.destroy) {
req.session.destroy();
}
if (req.session2 && req.session2.reset) {
req.session2.reset();
}
res.clearCookie('_UID', {
domain: 'yohobuy.com'
... ...