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({ @@ -69,7 +69,18 @@ passport.use('local', new LocalStrategy({
69 if (result.code && result.code === 200 && result.data.uid) { 69 if (result.code && result.code === 200 && result.data.uid) {
70 cache.del(errorLoginKey).catch(() => {}); 70 cache.del(errorLoginKey).catch(() => {});
71 71
72 - done(null, result.data); 72 + let uid = {
  73 + toString() {
  74 + return this.uid;
  75 + },
  76 + uid: result.data.uid,
  77 + sessionKey: result.data.session_key,
  78 + isValid() {
  79 + return this.uid && this.sessionKey;
  80 + }
  81 + };
  82 +
  83 + done(null, {uid, session_key: result.data.session_key});
73 } else { 84 } else {
74 errLoginTimes = errLoginTimes + 1; 85 errLoginTimes = errLoginTimes + 1;
75 accountTimes = accountTimes + 1; 86 accountTimes = accountTimes + 1;
@@ -212,7 +212,18 @@ const bind = { @@ -212,7 +212,18 @@ const bind = {
212 sourceType: sourceType + '_bind' 212 sourceType: sourceType + '_bind'
213 }); 213 });
214 214
215 - return loginService.syncUserSession(result.data.uid, req, res).then(() => { 215 + let uid = {
  216 + toString() {
  217 + return this.uid;
  218 + },
  219 + uid: result.data.uid,
  220 + sessionKey: result.data.session_key,
  221 + isValid() {
  222 + return this.uid && this.sessionKey;
  223 + }
  224 + };
  225 +
  226 + return loginService.syncUserSession(uid, req, res, result.data.session_key).then(() => {
216 return {code: 200, message: result.message, data: {refer: refer}}; 227 return {code: 200, message: result.message, data: {refer: refer}};
217 }); 228 });
218 } else { 229 } else {
@@ -246,7 +257,18 @@ const bind = { @@ -246,7 +257,18 @@ const bind = {
246 sourceType: sourceType + '_relate' 257 sourceType: sourceType + '_relate'
247 }); 258 });
248 259
249 - return loginService.syncUserSession(result.data.uid, req, res).then(() => { 260 + let uid = {
  261 + toString() {
  262 + return this.uid;
  263 + },
  264 + uid: result.data.uid,
  265 + sessionKey: result.data.session_key,
  266 + isValid() {
  267 + return this.uid && this.sessionKey;
  268 + }
  269 + };
  270 +
  271 + return loginService.syncUserSession(uid, req, res, result.data.session_key).then(() => {
250 return {code: 200, message: result.message, data: {refer: refer}}; 272 return {code: 200, message: result.message, data: {refer: refer}};
251 }); 273 });
252 } else { 274 } else {
@@ -282,7 +282,18 @@ let mobileRegister = (req, res, next) => { @@ -282,7 +282,18 @@ let mobileRegister = (req, res, next) => {
282 // 清除 session type 282 // 清除 session type
283 req.session.type = ''; 283 req.session.type = '';
284 284
285 - return loginService.syncUserSession(regResult.data.uid, req, res).then(() => { 285 + let uid = {
  286 + toString() {
  287 + return this.uid;
  288 + },
  289 + uid: result.data.uid,
  290 + sessionKey: result.data.session_key,
  291 + isValid() {
  292 + return this.uid && this.sessionKey;
  293 + }
  294 + };
  295 +
  296 + return loginService.syncUserSession(uid, req, res, regResult.data.session_key).then(() => {
286 return res.json({ 297 return res.json({
287 code: 200, 298 code: 200,
288 message: '注册成功', 299 message: '注册成功',
@@ -62,6 +62,7 @@ const syncUserSession = (uid, req, res, sessionKey) => { @@ -62,6 +62,7 @@ const syncUserSession = (uid, req, res, sessionKey) => {
62 res.cookie('isStudent', isStudent, { 62 res.cookie('isStudent', isStudent, {
63 domain: config.cookieDomain 63 domain: config.cookieDomain
64 }); 64 });
  65 +
65 res.cookie('_SESSION_KEY', authcode(sessionKey, '_SESSION_KEY', AUTH_TIME, 'encode'), { 66 res.cookie('_SESSION_KEY', authcode(sessionKey, '_SESSION_KEY', AUTH_TIME, 'encode'), {
66 domain: config.cookieDomain 67 domain: config.cookieDomain
67 }); 68 });
@@ -11,7 +11,7 @@ const isTest = process.env.NODE_ENV === 'test'; @@ -11,7 +11,7 @@ const isTest = process.env.NODE_ENV === 'test';
11 11
12 module.exports = { 12 module.exports = {
13 app: 'web', 13 app: 'web',
14 - appVersion: '5.5.0', // 调用api的版本 14 + appVersion: '5.5.1', // 调用api的版本
15 port: 6002, 15 port: 6002,
16 siteUrl: 'http://www.yohobuy.com', 16 siteUrl: 'http://www.yohobuy.com',
17 cookieDomain: '.yohobuy.com', 17 cookieDomain: '.yohobuy.com',
@@ -9,7 +9,7 @@ const authcode = require(`${global.utils}/authcode`); @@ -9,7 +9,7 @@ const authcode = require(`${global.utils}/authcode`);
9 // const cache = global.yoho.cache; 9 // const cache = global.yoho.cache;
10 10
11 function decrypt(word) { 11 function decrypt(word) {
12 - return authcode(word, '_SESSION_KEY'); 12 + return authcode(word, '_SESSION_KEY', 0, 'decode');
13 } 13 }
14 14
15 module.exports = () => { 15 module.exports = () => {
@@ -37,11 +37,12 @@ module.exports = () => { @@ -37,11 +37,12 @@ module.exports = () => {
37 return this.uid; 37 return this.uid;
38 }, 38 },
39 uid: cookie.getUid(req), 39 uid: cookie.getUid(req),
40 - sessionKey: decrypt(req.cookies._SESSION_KEY), 40 + sessionKey: decodeURIComponent(decrypt(req.cookies._SESSION_KEY)),
41 isValid() { 41 isValid() {
42 return this.uid && this.sessionKey; 42 return this.uid && this.sessionKey;
43 } 43 }
44 }; 44 };
  45 +
45 } 46 }
46 47
47 // 记住我 48 // 记住我