Authored by htoooth

调整登录的代码。

... ... @@ -269,30 +269,23 @@ const sina = {
* QQ登录
*/
const qq = {
login: (req, res, next) => {
req.session = req.session || {};
req.session.authState = uuid.v4();
return passport.authenticate('qq', {
state: req.session.authState
})(req, res, next);
login: (req, res) => {
let authState = req.session.authState = uuid.v4();
return res.redirect(`//www.yohobuy.com/passport/autosign/qq?type=yohoblk&state=${authState}`)
},
callback: (req, res, next) => {
if (req.session && req.session.authState && req.session.authState === req.query.state) {
passport.authenticate('qq', (err, user) => {
if (err) {
log.error(`qq authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPageURL);
}
let nickname = user.nickname;
let openId = user.id;
if (req.query.err) {
log.error(`qq authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPageURL);
}
_doPassportCallback(req, res, {
openId: openId,
nickname: nickname,
sourceType: 'qq'
}).catch(next);
})(req, res, next);
_doPassportCallback(req, res, {
openId: req.query.openid,
nickname: req.query.nickname,
sourceType: 'qq'
}).catch(next);
} else {
return next(new Error('Auth State Mismatch'));
}
... ...