Check if there is an account with a given email address when linking GitHub strategy.
This commit is contained in:
@ -108,6 +108,11 @@ passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refre
|
||||
} else {
|
||||
User.findOne({ github: profile.id }, function(err, existingUser) {
|
||||
if (existingUser) return done(null, existingUser);
|
||||
User.findOne({ email: profile._json.email }, function(err, existingEmailUser) {
|
||||
if (existingEmailUser) {
|
||||
req.flash('errors', { msg: 'There is already an account using this email address. Sign in to that account and link it with GitHub manually from Account Settings.' });
|
||||
done(err);
|
||||
} else {
|
||||
var user = new User();
|
||||
user.email = profile._json.email;
|
||||
user.github = profile.id;
|
||||
@ -119,6 +124,8 @@ passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refre
|
||||
user.save(function(err) {
|
||||
done(err, user);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
Reference in New Issue
Block a user