Check if there is an account with a given email address when linking GitHub strategy.
This commit is contained in:
@ -108,16 +108,23 @@ 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);
|
||||
var user = new User();
|
||||
user.email = profile._json.email;
|
||||
user.github = profile.id;
|
||||
user.tokens.push({ kind: 'github', accessToken: accessToken });
|
||||
user.profile.name = profile.displayName;
|
||||
user.profile.picture = profile._json.avatar_url;
|
||||
user.profile.location = profile._json.location;
|
||||
user.profile.website = profile._json.blog;
|
||||
user.save(function(err) {
|
||||
done(err, user);
|
||||
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;
|
||||
user.tokens.push({ kind: 'github', accessToken: accessToken });
|
||||
user.profile.name = profile.displayName;
|
||||
user.profile.picture = profile._json.avatar_url;
|
||||
user.profile.location = profile._json.location;
|
||||
user.profile.website = profile._json.blog;
|
||||
user.save(function(err) {
|
||||
done(err, user);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user