Authored by htoooth

Merge remote-tracking branch 'origin/feature/passport' into feature/passport

... ... @@ -11,6 +11,8 @@ const WeixinStrategy = require('passport-weixin');
const SinaStrategy = require('passport-sina').Strategy;
const LocalStrategy = require('passport-local').Strategy;
const QQStrategy = require('passport-qq').Strategy;
const DoubanStrategy = require('passport-douban').Strategy;
const RenrenStrategy = require('passport-renren').Strategy;
const AlipayStrategy = require('./models/passport-alipay').Strategy;
const md5 = require('md5');
... ... @@ -158,6 +160,24 @@ passport.use('alipay', new AlipayStrategy({
partner: '2088701661478015',
key: 'kcxawi9bb07mzh0aq2wcirsf9znusobw',
return_url: `${siteUrl}/passport/login/alipay/callback`
}), (profile, done) => {
}, (profile, done) => {
done(null, profile);
});
}));
// douban 登录
passport.use('douban', new DoubanStrategy({
clientID: '03b4e36bf13dc75a0b1eaa43d3b9560e',
clientSecret: 'f16d5913e8610672',
callbackURL: `${siteUrl}/passport/autosign/doubanback`
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
// renren 登录
passport.use('renren', new RenrenStrategy({
clientID: '783130c654c94a77ace97054ae266019',
clientSecret: '05e430de8c1e40d3a1f39ca8d3f8252c',
callbackURL: `${siteUrl}/passport/login/renren/callback`
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
... ...
... ... @@ -47,7 +47,7 @@ function doPassportCallback(req, res, user) {
user.nickname, user.openId, user.sourceType, shoppingKey);
}
signinByOpenID.then((result) => {
return signinByOpenID.then((result) => {
if (result.code !== 200) {
return Promise.reject(result);
}
... ... @@ -63,9 +63,7 @@ function doPassportCallback(req, res, user) {
});
}
}).then((redirectTo) => {
res.redirect(redirectTo);
}).catch(() => {
res.redirect(loginPage);
return res.redirect(redirectTo);
});
} else {
res.redirect(loginPage);
... ... @@ -229,7 +227,7 @@ const wechat = {
nickname: user._json.nickname || user.displayName,
sourceType: 'wechat',
rawUser: user
});
}).catch(next);
}
})(req, res, next);
} else {
... ... @@ -260,7 +258,7 @@ const sina = {
openId: openId,
nickname: nickname,
sourceType: 'sina'
});
}).catch(next);
})(req, res, next);
} else {
return next(new Error('Auth State Mismatch'));
... ... @@ -290,7 +288,7 @@ const qq = {
openId: openId,
nickname: nickname,
sourceType: 'qq'
});
}).catch(next);
})(req, res, next);
} else {
return next(new Error('Auth State Mismatch'));
... ... @@ -300,7 +298,6 @@ const qq = {
const alipay = {
login: (req, res, next) => {
log.info('goto alipay');
return passport.authenticate('alipay')(req, res, next);
},
callback: (req, res, next) => {
... ... @@ -316,7 +313,61 @@ const alipay = {
openId: openId,
nickname: nickname,
sourceType: 'alipay'
});
}).catch(next);
})(req, res, next);
}
};
const douban = {
login: (req, res, next) => {
req.session = req.session || {};
req.session.authState = uuid.v4();
return passport.authenticate('douban', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res, next) => {
passport.authenticate('douban', (err, user) => {
if (err) {
log.error(`douban authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPage);
}
let nickname = user.displayName;
let openId = user.id;
doPassportCallback(req, res, {
openId: openId,
nickname: nickname,
sourceType: 'douban'
}).catch(next);
})(req, res, next);
}
};
const renren = {
login: (req, res, next) => {
req.session = req.session || {};
req.session.authState = uuid.v4();
return passport.authenticate('renren', {
state: req.session.authState
})(req, res, next);
},
callback: (req, res, next) => {
passport.authenticate('renren', (err, user) => {
if (err) {
log.error(`renren authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPage);
}
let nickname = user.displayName;
let openId = user.id;
doPassportCallback(req, res, {
openId: openId,
nickname: nickname,
sourceType: 'renren'
}).catch(next);
})(req, res, next);
}
};
... ... @@ -327,5 +378,7 @@ module.exports = {
local: local,
sina: sina,
qq: qq,
alipay: alipay
alipay: alipay,
douban: douban,
renren: renren
};
... ...
... ... @@ -38,6 +38,13 @@ router.get('/login/qq/callback', login.qq.callback);
router.get('/autosign/alipay', login.common.beforeLogin, login.alipay.login);
router.get('/login/alipay/callback', login.alipay.callback);
// douban登录
router.get('/autosign/douban', login.common.beforeLogin, login.douban.login);
router.get('/autosign/doubanback', login.douban.callback);
// renren登录
router.get('/autosign/renren', login.common.beforeLogin, login.renren.login);
router.get('/login/renren/callback', login.renren.callback);
router.get('/login/account', login.common.needCaptcha);
... ...
... ... @@ -47,8 +47,10 @@
"morgan": "^1.7.0",
"oneapm": "^1.2.20",
"passport": "^0.3.2",
"passport-douban": "0.0.1",
"passport-local": "^1.0.0",
"passport-qq": "0.0.3",
"passport-renren": "^0.1.3",
"passport-sina": "^0.1.0",
"passport-strategy": "1.x.x",
"passport-weixin": "^0.1.0",
... ...
... ... @@ -47,13 +47,11 @@ handlebars.registerHelper('notzero', function(v1, options) {
});
function getSource(column, postition, event) {
try {
dataLayer.push({
louceng: column,
weizhi: postition,
event: event
});
} catch (e) {}
dataLayer.push({
louceng: column,
weizhi: postition,
event: event
});
}
function closeCover() {
... ... @@ -459,94 +457,92 @@ $subNav.on({
* @return {[type]} [description]
*/
function actionCover() {
var gender = window.cookie('_Gender');
// var gender = window.cookie('_Gender');
var newMask = '';
var windowheight = '';
var selfheight = '';
var containertop;
var length = '';
if (true) {
$.get('/guide', function(data) {
newMask = document.createElement('div');
newMask.id = 'cover';
newMask.innerHTML = data;
document.body.appendChild(newMask);
windowheight = $(window).height();
selfheight = $('.guide-box').height();
containertop = windowheight / 2 - selfheight / 2;
length = $('.guide-box .clear').find('li').length;
$('.guide-box').css({
width: (200 * length) + 'px',
top: containertop + 'px'
$.get('/guide', function(data) {
newMask = document.createElement('div');
newMask.id = 'cover';
newMask.innerHTML = data;
document.body.appendChild(newMask);
windowheight = $(window).height();
selfheight = $('.guide-box').height();
containertop = windowheight / 2 - selfheight / 2;
length = $('.guide-box .clear').find('li').length;
$('.guide-box').css({
width: (200 * length) + 'px',
top: containertop + 'px'
});
$('#cover').bind('click', function() {
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
$('#cover').bind('click', function(event) {
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
$('#cover .guide-box .close').bind('click', function(event) {
getSource('弹窗', 'CLOSE', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
closeCover();
});
$('#cover .guide-box .close').bind('click', function() {
getSource('弹窗', 'CLOSE', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
$('.boys img , .boys .go').bind('click', function(event) {
getSource('弹窗', 'BOYS', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
$('.girls img, .girls .go').bind('click', function(event) {
getSource('弹窗', 'GIRLS', 'homepage_woman');
window.setCookie('_Gender', '2,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'girls', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
closeCover();
});
$('.boys img , .boys .go').bind('click', function() {
getSource('弹窗', 'BOYS', 'homepage_man');
window.setCookie('_Gender', '1,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
$('.lifestyle img, .lifestyle .go').bind('click', function(event) {
window.setCookie('_Channel', 'lifestyle', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle');
window.setCookie('_Channel', 'boys', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
$('#cover .guide-box').bind('click', function(event) {
event.stopPropagation();
closeCover();
});
$('.girls img, .girls .go').bind('click', function() {
getSource('弹窗', 'GIRLS', 'homepage_woman');
window.setCookie('_Gender', '2,3', {
path: '/',
domain: '.yohobuy.com',
expires: 90
});
window.setCookie('_Channel', 'girls', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
});
}
$('.lifestyle img, .lifestyle .go').bind('click', function() {
window.setCookie('_Channel', 'lifestyle', {
path: '/',
domain: '.yohobuy.com',
expires: 7
});
getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle');
});
$('#cover .guide-box').bind('click', function(e) {
e.stopPropagation();
});
});
}
// actionCover();
actionCover();
... ...