Check if there is an account with provided email when linking with Facebook strategy
This commit is contained in:
@ -63,18 +63,24 @@ 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);
|
||||||
var user = new User();
|
User.findOne({ email: profile._json.email }, function(err, existingEmailUser) {
|
||||||
user.email = profile._json.email;
|
if (existingEmailUser) {
|
||||||
user.facebook = profile.id;
|
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.' });
|
||||||
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
done(err);
|
||||||
user.profile.name = profile.displayName;
|
} else {
|
||||||
user.profile.gender = profile._json.gender;
|
var user = new User();
|
||||||
user.profile.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
|
user.email = profile._json.email;
|
||||||
user.profile.location = (profile._json.location) ? profile._json.location.name : '';
|
user.facebook = profile.id;
|
||||||
user.save(function(err) {
|
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
||||||
done(err, user);
|
user.profile.name = profile.displayName;
|
||||||
|
user.profile.gender = profile._json.gender;
|
||||||
|
user.profile.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
|
||||||
|
user.profile.location = (profile._json.location) ? profile._json.location.name : '';
|
||||||
|
user.save(function(err) {
|
||||||
|
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