Authored by 陈峰

微信自动登录和登录上报

... ... @@ -74,6 +74,13 @@ const common = {
refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), {
domain: 'yohobuy.com'
});
next();
},
weixinCheck: (req, res, next) => {
if (req.yoho.isWechat) {
return res.redirect('/passport/login/wechat');
}
next();
}
};
... ... @@ -222,6 +229,9 @@ const local = {
user.session = refer;
user.href = refer;
res.cookie('_LOGIN_TYPE', 0, {
domain: 'm.yohobuy.com'
});
AuthHelper.syncUserSession(user.uid, req, res, user.session_key).then(() => {
res.json({
code: 200,
... ... @@ -273,6 +283,15 @@ const wechat = {
let nickname = user._json.nickname || user.displayName;
let openId = user._json.unionid || user.id;
res.cookie('_WX_OPENID', _.get(user, '_json.openid'), {
domain: 'm.yohobuy.com'
});
res.cookie('_WX_UNIONID', _.get(user, '_json.unionid'), {
domain: 'm.yohobuy.com'
});
res.cookie('_LOGIN_TYPE', 4, {
domain: 'm.yohobuy.com'
});
doPassportCallback(openId, nickname, 'wechat', req, res).catch(next);
})(req, res, next);
} else {
... ... @@ -301,6 +320,9 @@ const sina = {
let nickname = user.screen_name;
let openId = user.id;
res.cookie('_LOGIN_TYPE', 2, {
domain: 'm.yohobuy.com'
});
doPassportCallback(openId, nickname, 'sina', req, res).catch(next);
})(req, res, next);
} else {
... ... @@ -330,6 +352,9 @@ const qq = {
let nickname = user.nickname;
let openId = user.id;
res.cookie('_LOGIN_TYPE', 1, {
domain: 'm.yohobuy.com'
});
doPassportCallback(openId, nickname, 'qq', req, res).catch(next);
})(req, res, next);
} else {
... ... @@ -354,6 +379,9 @@ const alipay = {
let nickname = user.realName;
let openId = user.userId;
res.cookie('_LOGIN_TYPE', 3, {
domain: 'm.yohobuy.com'
});
doPassportCallback(openId, nickname, 'alipay', req, res).catch(next);
})(req, res, next);
}
... ...
... ... @@ -347,6 +347,9 @@ exports.check = (req, res, next) => {
return Promise.reject(info);
}
res.cookie('_LOGIN_TYPE', 5, {
domain: 'm.yohobuy.com'
});
return AuthHelper.syncUserSession(info.data.uid, req, res);
})
.then(() => {
... ...
... ... @@ -68,6 +68,10 @@ class Auth {
global.yoho.logger.error('write session key fail');
});
}
res.cookie('_LOGIN_IS_REPORT', false, {
domain: 'm.yohobuy.com',
path: '/'
});
return Auth.profile(uid).then((userInfo) => {
let salt = uuid.v4().substr(0, 8);
let saltedUid = uid + salt;
... ...
... ... @@ -28,7 +28,7 @@ const router = express.Router(); // eslint-disable-line
router.get('/passport/geetest/register', geetest.register);
// 兼容老的路由
router.get('/signin.html', validateCode.load, login.common.beforeLogin, smsLogin.loginPage);
router.get('/signin.html', validateCode.load, login.common.weixinCheck, login.common.beforeLogin, smsLogin.loginPage);
router.get('/reg.html', validateCode.load, disableBFCahce, reg.index);
router.get('/login.html', validateCode.load, login.common.beforeLogin, login.local.international);
router.get('/phoneback.html', back.indexMobilePage);
... ...
... ... @@ -10,8 +10,8 @@ const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
const domains = {
api: 'http://api-test3.yohops.com:9999/',
service: 'http://dev-service.yohops.com:9999/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
... ...
... ... @@ -412,6 +412,7 @@ function givePoint(parameter) {
}, true);
}
/**
* 页面头颜色修正
*/
... ... @@ -512,3 +513,5 @@ window._ChannelVary = _ChannelVary;
window.downLoadApp = downLoadApp;
window.mapSort = mapSort;
require('common/weixin-report');
... ...
let cookie = require('yoho-cookie');
let C_ID = window._ChannelVary[window.cookie('_Channel')];
(() => {
if (cookie.get('_LOGIN_IS_REPORT') === 'false' && cookie.get('_LOGIN_TYPE')) {
setTimeout(() => {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_LOGIN_SUCCESS_L',
param: JSON.stringify({
C_ID: C_ID,
LOGIN_TYPE: cookie.get('_LOGIN_TYPE'),
APP_TYPE: 1,
UNIONID: cookie.get('_WX_UNIONID') || void 0,
OPENID: cookie.get('_WX_OPENID') || void 0
})
}, true);
cookie.set('_LOGIN_IS_REPORT', true, {
domain: '.m.yohobuy.com',
path: '/'
});
}
}, 1000);
}
})();
... ...
let qs = require('yoho-qs');
let weixin = {
check: () => {
let isWechat = /micromessenger/i.test(navigator.userAgent || '');
if (isWechat) {
window.location.href = '/passport/login/wechat';
}
}
};
module.exports = weixin;
... ...