attempt to allow facebook login even with used email
This commit is contained in:
@ -41,10 +41,10 @@ passport.deserializeUser(function(id, done) {
|
|||||||
passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tokenSecret, profile, done) {
|
passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tokenSecret, profile, done) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
User.findOne({ twitter: profile.id }, function(err, existingUser) {
|
User.findOne({ twitter: profile.id }, function(err, existingUser) {
|
||||||
if (existingUser) {
|
//if (existingUser) {
|
||||||
req.flash('errors', { msg: 'There is already a Twitter account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
// req.flash('errors', { msg: 'There is already a Twitter account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
||||||
done(err);
|
// done(err);
|
||||||
} else {
|
//} else {
|
||||||
User.findById(req.user.id, function(err, user) {
|
User.findById(req.user.id, function(err, user) {
|
||||||
user.twitter = profile.id;
|
user.twitter = profile.id;
|
||||||
user.tokens.push({ kind: 'twitter', accessToken: accessToken, tokenSecret: tokenSecret });
|
user.tokens.push({ kind: 'twitter', accessToken: accessToken, tokenSecret: tokenSecret });
|
||||||
@ -57,7 +57,7 @@ passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tok
|
|||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
//}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -67,7 +67,7 @@ passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tok
|
|||||||
// Twitter will not provide an email address. Period.
|
// Twitter will not provide an email address. Period.
|
||||||
// But a person’s twitter username is guaranteed to be unique
|
// But a person’s twitter username is guaranteed to be unique
|
||||||
// so we can "fake" a twitter email address as follows:
|
// so we can "fake" a twitter email address as follows:
|
||||||
user.email = profile.username + "@twitter.com";
|
//user.email = profile.username + "@twitter.com";
|
||||||
user.twitter = profile.id;
|
user.twitter = profile.id;
|
||||||
user.tokens.push({ kind: 'twitter', accessToken: accessToken, tokenSecret: tokenSecret });
|
user.tokens.push({ kind: 'twitter', accessToken: accessToken, tokenSecret: tokenSecret });
|
||||||
user.profile.name = profile.displayName;
|
user.profile.name = profile.displayName;
|
||||||
@ -84,10 +84,10 @@ passport.use(new TwitterStrategy(secrets.twitter, function(req, accessToken, tok
|
|||||||
passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, refreshToken, profile, done) {
|
passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, refreshToken, profile, done) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
User.findOne({ linkedin: profile.id }, function(err, existingUser) {
|
User.findOne({ linkedin: profile.id }, function(err, existingUser) {
|
||||||
if (existingUser) {
|
//if (existingUser) {
|
||||||
req.flash('errors', { msg: 'There is already a LinkedIn account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
// req.flash('errors', { msg: 'There is already a LinkedIn account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
||||||
done(err);
|
// done(err);
|
||||||
} else {
|
//} else {
|
||||||
User.findById(req.user.id, function(err, user) {
|
User.findById(req.user.id, function(err, user) {
|
||||||
user.linkedin = profile.id;
|
user.linkedin = profile.id;
|
||||||
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
||||||
@ -100,16 +100,16 @@ passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, r
|
|||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
//}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
User.findOne({ linkedin: profile.id }, function(err, existingUser) {
|
User.findOne({ linkedin: profile.id }, function(err, existingUser) {
|
||||||
if (existingUser) return done(null, existingUser);
|
if (existingUser) return done(null, existingUser);
|
||||||
User.findOne({ email: profile._json.emailAddress }, function(err, existingEmailUser) {
|
User.findOne({ email: profile._json.emailAddress }, 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 LinkedIn 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 LinkedIn manually from Account Settings.' });
|
||||||
done(err);
|
// done(err);
|
||||||
} else {
|
//} else {
|
||||||
var user = new User();
|
var user = new User();
|
||||||
user.linkedin = profile.id;
|
user.linkedin = profile.id;
|
||||||
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
||||||
@ -121,7 +121,7 @@ passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, r
|
|||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
}
|
//}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,10 +147,10 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, function(email, passw
|
|||||||
passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, refreshToken, profile, done) {
|
passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, refreshToken, profile, done) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
User.findOne({ facebook: profile.id }, function(err, existingUser) {
|
User.findOne({ facebook: profile.id }, function(err, existingUser) {
|
||||||
if (existingUser) {
|
//if (existingUser) {
|
||||||
req.flash('errors', { msg: 'There is already a Facebook account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
// req.flash('errors', { msg: 'There is already a Facebook account that belongs to you. Sign in with that account or delete it, then link it with your current account.' });
|
||||||
done(err);
|
// done(err);
|
||||||
} else {
|
//} else {
|
||||||
User.findById(req.user.id, function(err, user) {
|
User.findById(req.user.id, function(err, user) {
|
||||||
user.facebook = profile.id;
|
user.facebook = profile.id;
|
||||||
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
||||||
@ -162,15 +162,26 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r
|
|||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
//}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
User.findOne({ facebook: profile.id }, function(err, existingUser) {
|
User.findOne({ facebook: profile.id }, function(err, existingUser) {
|
||||||
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 Facebook 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 Facebook manually from Account Settings.' });
|
||||||
done(err);
|
//done(err);
|
||||||
|
var user = existingEmailUser;
|
||||||
|
user.email = profile._json.email;
|
||||||
|
user.facebook = profile.id;
|
||||||
|
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
||||||
|
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);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
var user = new User();
|
var user = new User();
|
||||||
user.email = profile._json.email;
|
user.email = profile._json.email;
|
||||||
|
Reference in New Issue
Block a user