attempt to make facebook not overwrite
This commit is contained in:
@ -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,7 +100,7 @@ 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) {
|
||||||
@ -158,10 +158,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 });
|
||||||
@ -173,39 +173,24 @@ 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) {
|
var user = existingEmailUser || new User;
|
||||||
//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.email = user.email || profile._json.email;
|
||||||
//done(err);
|
user.facebook = profile.id;
|
||||||
var user = existingEmailUser;
|
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
||||||
user.email = profile._json.email;
|
user.profile.name = user.profile.name || profile.displayName;
|
||||||
user.facebook = profile.id;
|
user.profile.gender = user.profile.gender || profile._json.gender;
|
||||||
user.tokens.push({ kind: 'facebook', accessToken: accessToken });
|
user.profile.picture = user.profile.picture || 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
|
||||||
user.profile.name = profile.displayName;
|
user.profile.location = user.profile.location || (profile._json.location) ? profile._json.location.name : '';
|
||||||
user.profile.gender = profile._json.gender;
|
user.challengesComplete = user.challengesCompleted || [];
|
||||||
user.profile.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
|
user.save(function(err) {
|
||||||
user.profile.location = (profile._json.location) ? profile._json.location.name : '';
|
done(err, user);
|
||||||
user.save(function(err) {
|
});
|
||||||
done(err, user);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var user = new User();
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user