Authored by 周少峰

update session key

@@ -10,6 +10,17 @@ const passport = require('passport'); @@ -10,6 +10,17 @@ const passport = require('passport');
10 const uuid = require('uuid'); 10 const uuid = require('uuid');
11 const log = global.yoho.logger; 11 const log = global.yoho.logger;
12 const userService = require('../models/user-service'); 12 const userService = require('../models/user-service');
  13 +const config = global.yoho.config;
  14 +const authcode = require(`${global.utils}/authcode`);
  15 +const AUTH_TIME = 2592000000;
  16 +
  17 +const updateSessionKey = (res, sessionKey) => {
  18 + if (sessionKey) {
  19 + res.cookie('_SESSION_KEY', authcode(sessionKey, '_SESSION_KEY', AUTH_TIME, 'encode'), {
  20 + domain: config.cookieDomain
  21 + });
  22 + }
  23 +}
13 24
14 function bindSuccess(res, type) { 25 function bindSuccess(res, type) {
15 return res.render('home/user/bind-result', { 26 return res.render('home/user/bind-result', {
@@ -36,7 +47,9 @@ function bindFail(res, message, type) { @@ -36,7 +47,9 @@ function bindFail(res, message, type) {
36 const bind3party = (req, res, user) => { 47 const bind3party = (req, res, user) => {
37 userService.bind3partyAccount(req.user.uid, user) 48 userService.bind3partyAccount(req.user.uid, user)
38 .then(ret => { 49 .then(ret => {
  50 +
39 if (ret && ret.code === 200) { 51 if (ret && ret.code === 200) {
  52 + updateSessionKey(res, _.get(ret, 'data.session_key', ''));
40 return bindSuccess(res, user.sourceType); 53 return bindSuccess(res, user.sourceType);
41 } 54 }
42 return bindFail(res, ret && ret.message, user.sourceType); 55 return bindFail(res, ret && ret.message, user.sourceType);