Check if there is an account with provided email when linking with Facebook strategy
This commit is contained in:
@ -63,8 +63,12 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
User.findOne({ facebook: profile.id }, function(err, existingUser) {
|
User.findOne({ facebook: profile.id }, function(err, existingUser) {
|
||||||
console.log(profile)
|
|
||||||
if (existingUser) return done(null, 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 Facebook manually from Account Settings.' });
|
||||||
|
done(err);
|
||||||
|
} else {
|
||||||
var user = new User();
|
var user = new User();
|
||||||
user.email = profile._json.email;
|
user.email = profile._json.email;
|
||||||
user.facebook = profile.id;
|
user.facebook = profile.id;
|
||||||
@ -76,6 +80,8 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r
|
|||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -204,7 +210,7 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
|
|||||||
if (existingUser) return done(null, existingUser);
|
if (existingUser) return done(null, existingUser);
|
||||||
User.findOne({ email: profile._json.email }, function(err, existingEmailUser) {
|
User.findOne({ email: profile._json.email }, function(err, existingEmailUser) {
|
||||||
if(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.' });
|
req.flash('errors', { msg: 'There is already an account using this email address. Sign in to that account and link it with Google manually from Account Settings.' });
|
||||||
done(err);
|
done(err);
|
||||||
} else {
|
} else {
|
||||||
var user = new User();
|
var user = new User();
|
||||||
|
Reference in New Issue
Block a user