Authored by 陈峰

微信自动登录和登录上报

@@ -74,6 +74,13 @@ const common = { @@ -74,6 +74,13 @@ const common = {
74 refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), { 74 refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), {
75 domain: 'yohobuy.com' 75 domain: 'yohobuy.com'
76 }); 76 });
  77 +
  78 + next();
  79 + },
  80 + weixinCheck: (req, res, next) => {
  81 + if (req.yoho.isWechat) {
  82 + return res.redirect('/passport/login/wechat');
  83 + }
77 next(); 84 next();
78 } 85 }
79 }; 86 };
@@ -222,6 +229,9 @@ const local = { @@ -222,6 +229,9 @@ const local = {
222 229
223 user.session = refer; 230 user.session = refer;
224 user.href = refer; 231 user.href = refer;
  232 + res.cookie('_LOGIN_TYPE', 0, {
  233 + domain: 'm.yohobuy.com'
  234 + });
225 AuthHelper.syncUserSession(user.uid, req, res, user.session_key).then(() => { 235 AuthHelper.syncUserSession(user.uid, req, res, user.session_key).then(() => {
226 res.json({ 236 res.json({
227 code: 200, 237 code: 200,
@@ -273,6 +283,15 @@ const wechat = { @@ -273,6 +283,15 @@ const wechat = {
273 let nickname = user._json.nickname || user.displayName; 283 let nickname = user._json.nickname || user.displayName;
274 let openId = user._json.unionid || user.id; 284 let openId = user._json.unionid || user.id;
275 285
  286 + res.cookie('_WX_OPENID', _.get(user, '_json.openid'), {
  287 + domain: 'm.yohobuy.com'
  288 + });
  289 + res.cookie('_WX_UNIONID', _.get(user, '_json.unionid'), {
  290 + domain: 'm.yohobuy.com'
  291 + });
  292 + res.cookie('_LOGIN_TYPE', 4, {
  293 + domain: 'm.yohobuy.com'
  294 + });
276 doPassportCallback(openId, nickname, 'wechat', req, res).catch(next); 295 doPassportCallback(openId, nickname, 'wechat', req, res).catch(next);
277 })(req, res, next); 296 })(req, res, next);
278 } else { 297 } else {
@@ -301,6 +320,9 @@ const sina = { @@ -301,6 +320,9 @@ const sina = {
301 let nickname = user.screen_name; 320 let nickname = user.screen_name;
302 let openId = user.id; 321 let openId = user.id;
303 322
  323 + res.cookie('_LOGIN_TYPE', 2, {
  324 + domain: 'm.yohobuy.com'
  325 + });
304 doPassportCallback(openId, nickname, 'sina', req, res).catch(next); 326 doPassportCallback(openId, nickname, 'sina', req, res).catch(next);
305 })(req, res, next); 327 })(req, res, next);
306 } else { 328 } else {
@@ -330,6 +352,9 @@ const qq = { @@ -330,6 +352,9 @@ const qq = {
330 let nickname = user.nickname; 352 let nickname = user.nickname;
331 let openId = user.id; 353 let openId = user.id;
332 354
  355 + res.cookie('_LOGIN_TYPE', 1, {
  356 + domain: 'm.yohobuy.com'
  357 + });
333 doPassportCallback(openId, nickname, 'qq', req, res).catch(next); 358 doPassportCallback(openId, nickname, 'qq', req, res).catch(next);
334 })(req, res, next); 359 })(req, res, next);
335 } else { 360 } else {
@@ -354,6 +379,9 @@ const alipay = { @@ -354,6 +379,9 @@ const alipay = {
354 let nickname = user.realName; 379 let nickname = user.realName;
355 let openId = user.userId; 380 let openId = user.userId;
356 381
  382 + res.cookie('_LOGIN_TYPE', 3, {
  383 + domain: 'm.yohobuy.com'
  384 + });
357 doPassportCallback(openId, nickname, 'alipay', req, res).catch(next); 385 doPassportCallback(openId, nickname, 'alipay', req, res).catch(next);
358 })(req, res, next); 386 })(req, res, next);
359 } 387 }
@@ -347,6 +347,9 @@ exports.check = (req, res, next) => { @@ -347,6 +347,9 @@ exports.check = (req, res, next) => {
347 return Promise.reject(info); 347 return Promise.reject(info);
348 } 348 }
349 349
  350 + res.cookie('_LOGIN_TYPE', 5, {
  351 + domain: 'm.yohobuy.com'
  352 + });
350 return AuthHelper.syncUserSession(info.data.uid, req, res); 353 return AuthHelper.syncUserSession(info.data.uid, req, res);
351 }) 354 })
352 .then(() => { 355 .then(() => {
@@ -68,6 +68,10 @@ class Auth { @@ -68,6 +68,10 @@ class Auth {
68 global.yoho.logger.error('write session key fail'); 68 global.yoho.logger.error('write session key fail');
69 }); 69 });
70 } 70 }
  71 + res.cookie('_LOGIN_IS_REPORT', false, {
  72 + domain: 'm.yohobuy.com',
  73 + path: '/'
  74 + });
71 return Auth.profile(uid).then((userInfo) => { 75 return Auth.profile(uid).then((userInfo) => {
72 let salt = uuid.v4().substr(0, 8); 76 let salt = uuid.v4().substr(0, 8);
73 let saltedUid = uid + salt; 77 let saltedUid = uid + salt;
@@ -28,7 +28,7 @@ const router = express.Router(); // eslint-disable-line @@ -28,7 +28,7 @@ const router = express.Router(); // eslint-disable-line
28 router.get('/passport/geetest/register', geetest.register); 28 router.get('/passport/geetest/register', geetest.register);
29 29
30 // 兼容老的路由 30 // 兼容老的路由
31 -router.get('/signin.html', validateCode.load, login.common.beforeLogin, smsLogin.loginPage); 31 +router.get('/signin.html', validateCode.load, login.common.weixinCheck, login.common.beforeLogin, smsLogin.loginPage);
32 router.get('/reg.html', validateCode.load, disableBFCahce, reg.index); 32 router.get('/reg.html', validateCode.load, disableBFCahce, reg.index);
33 router.get('/login.html', validateCode.load, login.common.beforeLogin, login.local.international); 33 router.get('/login.html', validateCode.load, login.common.beforeLogin, login.local.international);
34 router.get('/phoneback.html', back.indexMobilePage); 34 router.get('/phoneback.html', back.indexMobilePage);
@@ -10,8 +10,8 @@ const isProduction = process.env.NODE_ENV === 'production'; @@ -10,8 +10,8 @@ const isProduction = process.env.NODE_ENV === 'production';
10 const isTest = process.env.NODE_ENV === 'test'; 10 const isTest = process.env.NODE_ENV === 'test';
11 11
12 const domains = { 12 const domains = {
13 - api: 'http://api-test3.yohops.com:9999/',  
14 - service: 'http://dev-service.yohops.com:9999/', 13 + api: 'http://api.yoho.cn/',
  14 + service: 'http://service.yoho.cn/',
15 liveApi: 'http://testapi.live.yohops.com:9999/', 15 liveApi: 'http://testapi.live.yohops.com:9999/',
16 singleApi: 'http://api-test3.yohops.com:9999/', 16 singleApi: 'http://api-test3.yohops.com:9999/',
17 17
@@ -412,6 +412,7 @@ function givePoint(parameter) { @@ -412,6 +412,7 @@ function givePoint(parameter) {
412 }, true); 412 }, true);
413 } 413 }
414 414
  415 +
415 /** 416 /**
416 * 页面头颜色修正 417 * 页面头颜色修正
417 */ 418 */
@@ -512,3 +513,5 @@ window._ChannelVary = _ChannelVary; @@ -512,3 +513,5 @@ window._ChannelVary = _ChannelVary;
512 window.downLoadApp = downLoadApp; 513 window.downLoadApp = downLoadApp;
513 514
514 window.mapSort = mapSort; 515 window.mapSort = mapSort;
  516 +
  517 +require('common/weixin-report');
  1 +
  2 +let cookie = require('yoho-cookie');
  3 +let C_ID = window._ChannelVary[window.cookie('_Channel')];
  4 +
  5 +(() => {
  6 + if (cookie.get('_LOGIN_IS_REPORT') === 'false' && cookie.get('_LOGIN_TYPE')) {
  7 + setTimeout(() => {
  8 + if (window._yas && window._yas.sendCustomInfo) {
  9 + window._yas.sendCustomInfo({
  10 + op: 'YB_LOGIN_SUCCESS_L',
  11 + param: JSON.stringify({
  12 + C_ID: C_ID,
  13 + LOGIN_TYPE: cookie.get('_LOGIN_TYPE'),
  14 + APP_TYPE: 1,
  15 + UNIONID: cookie.get('_WX_UNIONID') || void 0,
  16 + OPENID: cookie.get('_WX_OPENID') || void 0
  17 + })
  18 + }, true);
  19 + cookie.set('_LOGIN_IS_REPORT', true, {
  20 + domain: '.m.yohobuy.com',
  21 + path: '/'
  22 + });
  23 + }
  24 + }, 1000);
  25 + }
  26 +})();
  27 +
  1 +let qs = require('yoho-qs');
  2 +
  3 +let weixin = {
  4 + check: () => {
  5 + let isWechat = /micromessenger/i.test(navigator.userAgent || '');
  6 +
  7 + if (isWechat) {
  8 + window.location.href = '/passport/login/wechat';
  9 + }
  10 + }
  11 +};
  12 +
  13 +module.exports = weixin;