...
|
...
|
@@ -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
|
|
|
}; |
...
|
...
|
|