Authored by yyq

Merge branch 'feature/format' of git.yoho.cn:fe/yohobuy-node into feature/format

... ... @@ -69,7 +69,18 @@ passport.use('local', new LocalStrategy({
if (result.code && result.code === 200 && result.data.uid) {
cache.del(errorLoginKey).catch(() => {});
done(null, result.data);
let uid = {
toString() {
return this.uid;
},
uid: result.data.uid,
sessionKey: result.data.session_key,
isValid() {
return this.uid && this.sessionKey;
}
};
done(null, {uid, session_key: result.data.session_key});
} else {
errLoginTimes = errLoginTimes + 1;
accountTimes = accountTimes + 1;
... ...
... ... @@ -212,7 +212,18 @@ const bind = {
sourceType: sourceType + '_bind'
});
return loginService.syncUserSession(result.data.uid, req, res).then(() => {
let uid = {
toString() {
return this.uid;
},
uid: result.data.uid,
sessionKey: result.data.session_key,
isValid() {
return this.uid && this.sessionKey;
}
};
return loginService.syncUserSession(uid, req, res, result.data.session_key).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
} else {
... ... @@ -246,7 +257,18 @@ const bind = {
sourceType: sourceType + '_relate'
});
return loginService.syncUserSession(result.data.uid, req, res).then(() => {
let uid = {
toString() {
return this.uid;
},
uid: result.data.uid,
sessionKey: result.data.session_key,
isValid() {
return this.uid && this.sessionKey;
}
};
return loginService.syncUserSession(uid, req, res, result.data.session_key).then(() => {
return {code: 200, message: result.message, data: {refer: refer}};
});
} else {
... ...
... ... @@ -282,7 +282,18 @@ let mobileRegister = (req, res, next) => {
// 清除 session type
req.session.type = '';
return loginService.syncUserSession(regResult.data.uid, req, res).then(() => {
let uid = {
toString() {
return this.uid;
},
uid: result.data.uid,
sessionKey: result.data.session_key,
isValid() {
return this.uid && this.sessionKey;
}
};
return loginService.syncUserSession(uid, req, res, regResult.data.session_key).then(() => {
return res.json({
code: 200,
message: '注册成功',
... ...
... ... @@ -62,6 +62,7 @@ const syncUserSession = (uid, req, res, sessionKey) => {
res.cookie('isStudent', isStudent, {
domain: config.cookieDomain
});
res.cookie('_SESSION_KEY', authcode(sessionKey, '_SESSION_KEY', AUTH_TIME, 'encode'), {
domain: config.cookieDomain
});
... ...
... ... @@ -11,7 +11,7 @@ const isTest = process.env.NODE_ENV === 'test';
module.exports = {
app: 'web',
appVersion: '5.5.0', // 调用api的版本
appVersion: '5.5.1', // 调用api的版本
port: 6002,
siteUrl: 'http://www.yohobuy.com',
cookieDomain: '.yohobuy.com',
... ...
... ... @@ -9,7 +9,7 @@ const authcode = require(`${global.utils}/authcode`);
// const cache = global.yoho.cache;
function decrypt(word) {
return authcode(word, '_SESSION_KEY');
return authcode(word, '_SESSION_KEY', 0, 'decode');
}
module.exports = () => {
... ... @@ -37,11 +37,12 @@ module.exports = () => {
return this.uid;
},
uid: cookie.getUid(req),
sessionKey: decrypt(req.cookies._SESSION_KEY),
sessionKey: decodeURIComponent(decrypt(req.cookies._SESSION_KEY)),
isValid() {
return this.uid && this.sessionKey;
}
};
}
// 记住我
... ...