From beaba3bf88ae785a26f9b426ea15727412f7bb2f Mon Sep 17 00:00:00 2001 From: alsotang Date: Mon, 23 Nov 2015 16:29:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E4=BF=AE=E8=A1=A5=20passport?= =?UTF-8?q?-github=20=E5=8D=87=E7=BA=A7=E5=90=8E=E7=9A=84=20emails=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/github.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/controllers/github.js b/controllers/github.js index d3d7cd4..53074c9 100644 --- a/controllers/github.js +++ b/controllers/github.js @@ -8,6 +8,7 @@ var validator = require('validator'); exports.callback = function (req, res, next) { var profile = req.user; + var email = profile.emails && profile.emails[0] && profile.emails[0].value; User.findOne({githubId: profile.id}, function (err, user) { if (err) { return next(err); @@ -19,9 +20,8 @@ exports.callback = function (req, res, next) { user.githubAccessToken = profile.accessToken; // user.loginname = profile.username; user.avatar = profile._json.avatar_url; - if (profile.emails && profile.emails[0] && profile.emails[0].value) { - user.email = profile.emails[0].value; - } + user.email = email; + user.save(function (err) { if (err) { @@ -44,6 +44,7 @@ exports.new = function (req, res, next) { exports.create = function (req, res, next) { var profile = req.session.profile; + var email = profile.emails && profile.emails[0] && profile.emails[0].value; var isnew = req.body.isnew; var loginname = validator.trim(req.body.name).toLowerCase(); var password = validator.trim(req.body.pass); @@ -58,7 +59,7 @@ exports.create = function (req, res, next) { var user = new User({ loginname: profile.username, pass: profile.accessToken, - email: profile.emails[0].value, + email: email, avatar: profile._json.avatar_url, githubId: profile.id, githubUsername: profile.username,