Merge remote-tracking branch 'origin/feature/passport' into feature/passport
Showing
5 changed files
with
172 additions
and
94 deletions
@@ -11,6 +11,8 @@ const WeixinStrategy = require('passport-weixin'); | @@ -11,6 +11,8 @@ const WeixinStrategy = require('passport-weixin'); | ||
11 | const SinaStrategy = require('passport-sina').Strategy; | 11 | const SinaStrategy = require('passport-sina').Strategy; |
12 | const LocalStrategy = require('passport-local').Strategy; | 12 | const LocalStrategy = require('passport-local').Strategy; |
13 | const QQStrategy = require('passport-qq').Strategy; | 13 | const QQStrategy = require('passport-qq').Strategy; |
14 | +const DoubanStrategy = require('passport-douban').Strategy; | ||
15 | +const RenrenStrategy = require('passport-renren').Strategy; | ||
14 | const AlipayStrategy = require('./models/passport-alipay').Strategy; | 16 | const AlipayStrategy = require('./models/passport-alipay').Strategy; |
15 | 17 | ||
16 | const md5 = require('md5'); | 18 | const md5 = require('md5'); |
@@ -158,6 +160,24 @@ passport.use('alipay', new AlipayStrategy({ | @@ -158,6 +160,24 @@ passport.use('alipay', new AlipayStrategy({ | ||
158 | partner: '2088701661478015', | 160 | partner: '2088701661478015', |
159 | key: 'kcxawi9bb07mzh0aq2wcirsf9znusobw', | 161 | key: 'kcxawi9bb07mzh0aq2wcirsf9znusobw', |
160 | return_url: `${siteUrl}/passport/login/alipay/callback` | 162 | return_url: `${siteUrl}/passport/login/alipay/callback` |
161 | -}), (profile, done) => { | 163 | +}, (profile, done) => { |
162 | done(null, profile); | 164 | done(null, profile); |
163 | -}); | 165 | +})); |
166 | + | ||
167 | +// douban 登录 | ||
168 | +passport.use('douban', new DoubanStrategy({ | ||
169 | + clientID: '03b4e36bf13dc75a0b1eaa43d3b9560e', | ||
170 | + clientSecret: 'f16d5913e8610672', | ||
171 | + callbackURL: `${siteUrl}/passport/autosign/doubanback` | ||
172 | +}, (accessToken, refreshToken, profile, done) => { | ||
173 | + done(null, profile); | ||
174 | +})); | ||
175 | + | ||
176 | +// renren 登录 | ||
177 | +passport.use('renren', new RenrenStrategy({ | ||
178 | + clientID: '783130c654c94a77ace97054ae266019', | ||
179 | + clientSecret: '05e430de8c1e40d3a1f39ca8d3f8252c', | ||
180 | + callbackURL: `${siteUrl}/passport/login/renren/callback` | ||
181 | +}, (accessToken, refreshToken, profile, done) => { | ||
182 | + done(null, profile); | ||
183 | +})); |
@@ -47,7 +47,7 @@ function doPassportCallback(req, res, user) { | @@ -47,7 +47,7 @@ function doPassportCallback(req, res, user) { | ||
47 | user.nickname, user.openId, user.sourceType, shoppingKey); | 47 | user.nickname, user.openId, user.sourceType, shoppingKey); |
48 | } | 48 | } |
49 | 49 | ||
50 | - signinByOpenID.then((result) => { | 50 | + return signinByOpenID.then((result) => { |
51 | if (result.code !== 200) { | 51 | if (result.code !== 200) { |
52 | return Promise.reject(result); | 52 | return Promise.reject(result); |
53 | } | 53 | } |
@@ -63,9 +63,7 @@ function doPassportCallback(req, res, user) { | @@ -63,9 +63,7 @@ function doPassportCallback(req, res, user) { | ||
63 | }); | 63 | }); |
64 | } | 64 | } |
65 | }).then((redirectTo) => { | 65 | }).then((redirectTo) => { |
66 | - res.redirect(redirectTo); | ||
67 | - }).catch(() => { | ||
68 | - res.redirect(loginPage); | 66 | + return res.redirect(redirectTo); |
69 | }); | 67 | }); |
70 | } else { | 68 | } else { |
71 | res.redirect(loginPage); | 69 | res.redirect(loginPage); |
@@ -229,7 +227,7 @@ const wechat = { | @@ -229,7 +227,7 @@ const wechat = { | ||
229 | nickname: user._json.nickname || user.displayName, | 227 | nickname: user._json.nickname || user.displayName, |
230 | sourceType: 'wechat', | 228 | sourceType: 'wechat', |
231 | rawUser: user | 229 | rawUser: user |
232 | - }); | 230 | + }).catch(next); |
233 | } | 231 | } |
234 | })(req, res, next); | 232 | })(req, res, next); |
235 | } else { | 233 | } else { |
@@ -260,7 +258,7 @@ const sina = { | @@ -260,7 +258,7 @@ const sina = { | ||
260 | openId: openId, | 258 | openId: openId, |
261 | nickname: nickname, | 259 | nickname: nickname, |
262 | sourceType: 'sina' | 260 | sourceType: 'sina' |
263 | - }); | 261 | + }).catch(next); |
264 | })(req, res, next); | 262 | })(req, res, next); |
265 | } else { | 263 | } else { |
266 | return next(new Error('Auth State Mismatch')); | 264 | return next(new Error('Auth State Mismatch')); |
@@ -290,7 +288,7 @@ const qq = { | @@ -290,7 +288,7 @@ const qq = { | ||
290 | openId: openId, | 288 | openId: openId, |
291 | nickname: nickname, | 289 | nickname: nickname, |
292 | sourceType: 'qq' | 290 | sourceType: 'qq' |
293 | - }); | 291 | + }).catch(next); |
294 | })(req, res, next); | 292 | })(req, res, next); |
295 | } else { | 293 | } else { |
296 | return next(new Error('Auth State Mismatch')); | 294 | return next(new Error('Auth State Mismatch')); |
@@ -300,7 +298,6 @@ const qq = { | @@ -300,7 +298,6 @@ const qq = { | ||
300 | 298 | ||
301 | const alipay = { | 299 | const alipay = { |
302 | login: (req, res, next) => { | 300 | login: (req, res, next) => { |
303 | - log.info('goto alipay'); | ||
304 | return passport.authenticate('alipay')(req, res, next); | 301 | return passport.authenticate('alipay')(req, res, next); |
305 | }, | 302 | }, |
306 | callback: (req, res, next) => { | 303 | callback: (req, res, next) => { |
@@ -316,7 +313,61 @@ const alipay = { | @@ -316,7 +313,61 @@ const alipay = { | ||
316 | openId: openId, | 313 | openId: openId, |
317 | nickname: nickname, | 314 | nickname: nickname, |
318 | sourceType: 'alipay' | 315 | sourceType: 'alipay' |
319 | - }); | 316 | + }).catch(next); |
317 | + })(req, res, next); | ||
318 | + } | ||
319 | +}; | ||
320 | + | ||
321 | +const douban = { | ||
322 | + login: (req, res, next) => { | ||
323 | + req.session = req.session || {}; | ||
324 | + req.session.authState = uuid.v4(); | ||
325 | + return passport.authenticate('douban', { | ||
326 | + state: req.session.authState | ||
327 | + })(req, res, next); | ||
328 | + }, | ||
329 | + callback: (req, res, next) => { | ||
330 | + passport.authenticate('douban', (err, user) => { | ||
331 | + if (err) { | ||
332 | + log.error(`douban authenticate error : ${JSON.stringify(err)}`); | ||
333 | + return res.redirect(loginPage); | ||
334 | + } | ||
335 | + | ||
336 | + let nickname = user.displayName; | ||
337 | + let openId = user.id; | ||
338 | + | ||
339 | + doPassportCallback(req, res, { | ||
340 | + openId: openId, | ||
341 | + nickname: nickname, | ||
342 | + sourceType: 'douban' | ||
343 | + }).catch(next); | ||
344 | + })(req, res, next); | ||
345 | + } | ||
346 | +}; | ||
347 | + | ||
348 | +const renren = { | ||
349 | + login: (req, res, next) => { | ||
350 | + req.session = req.session || {}; | ||
351 | + req.session.authState = uuid.v4(); | ||
352 | + return passport.authenticate('renren', { | ||
353 | + state: req.session.authState | ||
354 | + })(req, res, next); | ||
355 | + }, | ||
356 | + callback: (req, res, next) => { | ||
357 | + passport.authenticate('renren', (err, user) => { | ||
358 | + if (err) { | ||
359 | + log.error(`renren authenticate error : ${JSON.stringify(err)}`); | ||
360 | + return res.redirect(loginPage); | ||
361 | + } | ||
362 | + | ||
363 | + let nickname = user.displayName; | ||
364 | + let openId = user.id; | ||
365 | + | ||
366 | + doPassportCallback(req, res, { | ||
367 | + openId: openId, | ||
368 | + nickname: nickname, | ||
369 | + sourceType: 'renren' | ||
370 | + }).catch(next); | ||
320 | })(req, res, next); | 371 | })(req, res, next); |
321 | } | 372 | } |
322 | }; | 373 | }; |
@@ -327,5 +378,7 @@ module.exports = { | @@ -327,5 +378,7 @@ module.exports = { | ||
327 | local: local, | 378 | local: local, |
328 | sina: sina, | 379 | sina: sina, |
329 | qq: qq, | 380 | qq: qq, |
330 | - alipay: alipay | 381 | + alipay: alipay, |
382 | + douban: douban, | ||
383 | + renren: renren | ||
331 | }; | 384 | }; |
@@ -38,6 +38,13 @@ router.get('/login/qq/callback', login.qq.callback); | @@ -38,6 +38,13 @@ router.get('/login/qq/callback', login.qq.callback); | ||
38 | router.get('/autosign/alipay', login.common.beforeLogin, login.alipay.login); | 38 | router.get('/autosign/alipay', login.common.beforeLogin, login.alipay.login); |
39 | router.get('/login/alipay/callback', login.alipay.callback); | 39 | router.get('/login/alipay/callback', login.alipay.callback); |
40 | 40 | ||
41 | +// douban登录 | ||
42 | +router.get('/autosign/douban', login.common.beforeLogin, login.douban.login); | ||
43 | +router.get('/autosign/doubanback', login.douban.callback); | ||
44 | + | ||
45 | +// renren登录 | ||
46 | +router.get('/autosign/renren', login.common.beforeLogin, login.renren.login); | ||
47 | +router.get('/login/renren/callback', login.renren.callback); | ||
41 | 48 | ||
42 | router.get('/login/account', login.common.needCaptcha); | 49 | router.get('/login/account', login.common.needCaptcha); |
43 | 50 |
@@ -47,8 +47,10 @@ | @@ -47,8 +47,10 @@ | ||
47 | "morgan": "^1.7.0", | 47 | "morgan": "^1.7.0", |
48 | "oneapm": "^1.2.20", | 48 | "oneapm": "^1.2.20", |
49 | "passport": "^0.3.2", | 49 | "passport": "^0.3.2", |
50 | + "passport-douban": "0.0.1", | ||
50 | "passport-local": "^1.0.0", | 51 | "passport-local": "^1.0.0", |
51 | "passport-qq": "0.0.3", | 52 | "passport-qq": "0.0.3", |
53 | + "passport-renren": "^0.1.3", | ||
52 | "passport-sina": "^0.1.0", | 54 | "passport-sina": "^0.1.0", |
53 | "passport-strategy": "1.x.x", | 55 | "passport-strategy": "1.x.x", |
54 | "passport-weixin": "^0.1.0", | 56 | "passport-weixin": "^0.1.0", |
@@ -47,13 +47,11 @@ handlebars.registerHelper('notzero', function(v1, options) { | @@ -47,13 +47,11 @@ handlebars.registerHelper('notzero', function(v1, options) { | ||
47 | }); | 47 | }); |
48 | 48 | ||
49 | function getSource(column, postition, event) { | 49 | function getSource(column, postition, event) { |
50 | - try { | ||
51 | - dataLayer.push({ | ||
52 | - louceng: column, | ||
53 | - weizhi: postition, | ||
54 | - event: event | ||
55 | - }); | ||
56 | - } catch (e) {} | 50 | + dataLayer.push({ |
51 | + louceng: column, | ||
52 | + weizhi: postition, | ||
53 | + event: event | ||
54 | + }); | ||
57 | } | 55 | } |
58 | 56 | ||
59 | function closeCover() { | 57 | function closeCover() { |
@@ -459,94 +457,92 @@ $subNav.on({ | @@ -459,94 +457,92 @@ $subNav.on({ | ||
459 | * @return {[type]} [description] | 457 | * @return {[type]} [description] |
460 | */ | 458 | */ |
461 | function actionCover() { | 459 | function actionCover() { |
462 | - var gender = window.cookie('_Gender'); | 460 | + // var gender = window.cookie('_Gender'); |
463 | var newMask = ''; | 461 | var newMask = ''; |
464 | var windowheight = ''; | 462 | var windowheight = ''; |
465 | var selfheight = ''; | 463 | var selfheight = ''; |
466 | var containertop; | 464 | var containertop; |
467 | var length = ''; | 465 | var length = ''; |
468 | 466 | ||
469 | - if (true) { | ||
470 | - $.get('/guide', function(data) { | ||
471 | - newMask = document.createElement('div'); | ||
472 | - newMask.id = 'cover'; | ||
473 | - newMask.innerHTML = data; | ||
474 | - document.body.appendChild(newMask); | ||
475 | - windowheight = $(window).height(); | ||
476 | - selfheight = $('.guide-box').height(); | ||
477 | - containertop = windowheight / 2 - selfheight / 2; | ||
478 | - length = $('.guide-box .clear').find('li').length; | ||
479 | - $('.guide-box').css({ | ||
480 | - width: (200 * length) + 'px', | ||
481 | - top: containertop + 'px' | 467 | + $.get('/guide', function(data) { |
468 | + newMask = document.createElement('div'); | ||
469 | + newMask.id = 'cover'; | ||
470 | + newMask.innerHTML = data; | ||
471 | + document.body.appendChild(newMask); | ||
472 | + windowheight = $(window).height(); | ||
473 | + selfheight = $('.guide-box').height(); | ||
474 | + containertop = windowheight / 2 - selfheight / 2; | ||
475 | + length = $('.guide-box .clear').find('li').length; | ||
476 | + $('.guide-box').css({ | ||
477 | + width: (200 * length) + 'px', | ||
478 | + top: containertop + 'px' | ||
479 | + }); | ||
480 | + $('#cover').bind('click', function() { | ||
481 | + window.setCookie('_Gender', '1,3', { | ||
482 | + path: '/', | ||
483 | + domain: '.yohobuy.com', | ||
484 | + expires: 90 | ||
482 | }); | 485 | }); |
483 | - $('#cover').bind('click', function(event) { | ||
484 | - window.setCookie('_Gender', '1,3', { | ||
485 | - path: '/', | ||
486 | - domain: '.yohobuy.com', | ||
487 | - expires: 90 | ||
488 | - }); | ||
489 | - window.setCookie('_Channel', 'boys', { | ||
490 | - path: '/', | ||
491 | - domain: '.yohobuy.com', | ||
492 | - expires: 7 | ||
493 | - }); | ||
494 | - closeCover(); | 486 | + window.setCookie('_Channel', 'boys', { |
487 | + path: '/', | ||
488 | + domain: '.yohobuy.com', | ||
489 | + expires: 7 | ||
495 | }); | 490 | }); |
496 | - $('#cover .guide-box .close').bind('click', function(event) { | ||
497 | - getSource('弹窗', 'CLOSE', 'homepage_man'); | ||
498 | - window.setCookie('_Gender', '1,3', { | ||
499 | - path: '/', | ||
500 | - domain: '.yohobuy.com', | ||
501 | - expires: 90 | ||
502 | - }); | ||
503 | - window.setCookie('_Channel', 'boys', { | ||
504 | - path: '/', | ||
505 | - domain: '.yohobuy.com', | ||
506 | - expires: 7 | ||
507 | - }); | ||
508 | - closeCover(); | 491 | + closeCover(); |
492 | + }); | ||
493 | + $('#cover .guide-box .close').bind('click', function() { | ||
494 | + getSource('弹窗', 'CLOSE', 'homepage_man'); | ||
495 | + window.setCookie('_Gender', '1,3', { | ||
496 | + path: '/', | ||
497 | + domain: '.yohobuy.com', | ||
498 | + expires: 90 | ||
509 | }); | 499 | }); |
510 | - $('.boys img , .boys .go').bind('click', function(event) { | ||
511 | - getSource('弹窗', 'BOYS', 'homepage_man'); | ||
512 | - window.setCookie('_Gender', '1,3', { | ||
513 | - path: '/', | ||
514 | - domain: '.yohobuy.com', | ||
515 | - expires: 90 | ||
516 | - }); | ||
517 | - window.setCookie('_Channel', 'boys', { | ||
518 | - path: '/', | ||
519 | - domain: '.yohobuy.com', | ||
520 | - expires: 7 | ||
521 | - }); | ||
522 | - closeCover(); | 500 | + window.setCookie('_Channel', 'boys', { |
501 | + path: '/', | ||
502 | + domain: '.yohobuy.com', | ||
503 | + expires: 7 | ||
523 | }); | 504 | }); |
524 | - $('.girls img, .girls .go').bind('click', function(event) { | ||
525 | - getSource('弹窗', 'GIRLS', 'homepage_woman'); | ||
526 | - window.setCookie('_Gender', '2,3', { | ||
527 | - path: '/', | ||
528 | - domain: '.yohobuy.com', | ||
529 | - expires: 90 | ||
530 | - }); | ||
531 | - window.setCookie('_Channel', 'girls', { | ||
532 | - path: '/', | ||
533 | - domain: '.yohobuy.com', | ||
534 | - expires: 7 | ||
535 | - }); | 505 | + closeCover(); |
506 | + }); | ||
507 | + $('.boys img , .boys .go').bind('click', function() { | ||
508 | + getSource('弹窗', 'BOYS', 'homepage_man'); | ||
509 | + window.setCookie('_Gender', '1,3', { | ||
510 | + path: '/', | ||
511 | + domain: '.yohobuy.com', | ||
512 | + expires: 90 | ||
536 | }); | 513 | }); |
537 | - $('.lifestyle img, .lifestyle .go').bind('click', function(event) { | ||
538 | - window.setCookie('_Channel', 'lifestyle', { | ||
539 | - path: '/', | ||
540 | - domain: '.yohobuy.com', | ||
541 | - expires: 7 | ||
542 | - }); | ||
543 | - getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle'); | 514 | + window.setCookie('_Channel', 'boys', { |
515 | + path: '/', | ||
516 | + domain: '.yohobuy.com', | ||
517 | + expires: 7 | ||
544 | }); | 518 | }); |
545 | - $('#cover .guide-box').bind('click', function(event) { | ||
546 | - event.stopPropagation(); | 519 | + closeCover(); |
520 | + }); | ||
521 | + $('.girls img, .girls .go').bind('click', function() { | ||
522 | + getSource('弹窗', 'GIRLS', 'homepage_woman'); | ||
523 | + window.setCookie('_Gender', '2,3', { | ||
524 | + path: '/', | ||
525 | + domain: '.yohobuy.com', | ||
526 | + expires: 90 | ||
527 | + }); | ||
528 | + window.setCookie('_Channel', 'girls', { | ||
529 | + path: '/', | ||
530 | + domain: '.yohobuy.com', | ||
531 | + expires: 7 | ||
547 | }); | 532 | }); |
548 | }); | 533 | }); |
549 | - } | 534 | + $('.lifestyle img, .lifestyle .go').bind('click', function() { |
535 | + window.setCookie('_Channel', 'lifestyle', { | ||
536 | + path: '/', | ||
537 | + domain: '.yohobuy.com', | ||
538 | + expires: 7 | ||
539 | + }); | ||
540 | + getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle'); | ||
541 | + }); | ||
542 | + $('#cover .guide-box').bind('click', function(e) { | ||
543 | + e.stopPropagation(); | ||
544 | + }); | ||
545 | + }); | ||
550 | } | 546 | } |
551 | 547 | ||
552 | -// actionCover(); | 548 | +actionCover(); |
-
Please register or login to post a comment