update other authentication methods
This commit is contained in:
@ -106,33 +106,18 @@ passport.use(new LinkedInStrategy(secrets.linkedin, function(req, accessToken, r
|
|||||||
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) {
|
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 LinkedIn manually from Account Settings.' });
|
user.linkedin = profile.id;
|
||||||
// done(err);
|
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
||||||
var user = existingEmailUser;
|
user.email = profile._json.emailAddress;
|
||||||
user.linkedin = profile.id;
|
user.profile.name = user.profile.name || profile.displayName;
|
||||||
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
user.profile.location = user.profile.location || profile._json.location.name;
|
||||||
user.email = profile._json.emailAddress;
|
user.profile.picture = user.profile.picture || profile._json.pictureUrl;
|
||||||
user.profile.name = profile.displayName;
|
user.profile.website = user.profile.website || profile._json.publicProfileUrl;
|
||||||
user.profile.location = profile._json.location.name;
|
user.challengesComplete = user.challengesCompleted || [];
|
||||||
user.profile.picture = profile._json.pictureUrl;
|
user.save(function(err) {
|
||||||
user.profile.website = profile._json.publicProfileUrl;
|
done(err, user);
|
||||||
user.save(function(err) {
|
});
|
||||||
done(err, user);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var user = new User();
|
|
||||||
user.linkedin = profile.id;
|
|
||||||
user.tokens.push({ kind: 'linkedin', accessToken: accessToken });
|
|
||||||
user.email = profile._json.emailAddress;
|
|
||||||
user.profile.name = profile.displayName;
|
|
||||||
user.profile.location = profile._json.location.name;
|
|
||||||
user.profile.picture = profile._json.pictureUrl;
|
|
||||||
user.profile.website = profile._json.publicProfileUrl;
|
|
||||||
user.save(function(err) {
|
|
||||||
done(err, user);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -201,10 +186,10 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r
|
|||||||
passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refreshToken, profile, done) {
|
passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refreshToken, profile, done) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
User.findOne({ github: profile.id }, function(err, existingUser) {
|
User.findOne({ github: profile.id }, function(err, existingUser) {
|
||||||
//if (existingUser) {
|
if (existingUser) {
|
||||||
// req.flash('errors', { msg: 'There is already a GitHub 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 GitHub 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.github = profile.id;
|
user.github = profile.id;
|
||||||
user.tokens.push({ kind: 'github', accessToken: accessToken });
|
user.tokens.push({ kind: 'github', accessToken: accessToken });
|
||||||
@ -217,54 +202,37 @@ passport.use(new GitHubStrategy(secrets.github, function(req, accessToken, refre
|
|||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
User.findOne({ github: profile.id }, function(err, existingUser) {
|
User.findOne({ github: 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 GitHub manually from Account Settings.' });
|
user.email = profile._json.email;
|
||||||
//done(err);
|
user.github = profile.id;
|
||||||
var user = existingEmailUser;
|
user.tokens.push({ kind: 'github', accessToken: accessToken });
|
||||||
user.email = profile._json.email;
|
user.profile.name = user.profile.name || profile.displayName;
|
||||||
user.github = profile.id;
|
user.profile.picture = user.profile.picture || profile._json.avatar_url;
|
||||||
user.tokens.push({ kind: 'github', accessToken: accessToken });
|
user.profile.location = user.profile.location || profile._json.location;
|
||||||
user.profile.name = profile.displayName;
|
user.profile.website = user.profile.website || profile._json.blog;
|
||||||
user.profile.picture = profile._json.avatar_url;
|
user.save(function(err) {
|
||||||
user.profile.location = profile._json.location;
|
done(err, user);
|
||||||
user.profile.website = profile._json.blog;
|
});
|
||||||
user.save(function(err) {
|
|
||||||
done(err, user);
|
|
||||||
});
|
|
||||||
} 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
// Sign in with Google.
|
// Sign in with Google.
|
||||||
|
|
||||||
passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refreshToken, profile, done) {
|
passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refreshToken, profile, done) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
User.findOne({ google: profile.id }, function(err, existingUser) {
|
User.findOne({ google: profile.id }, function(err, existingUser) {
|
||||||
//if (existingUser) {
|
if (existingUser) {
|
||||||
// req.flash('errors', { msg: 'There is already a Google 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 Google 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.google = profile.id;
|
user.google = profile.id;
|
||||||
user.tokens.push({ kind: 'google', accessToken: accessToken });
|
user.tokens.push({ kind: 'google', accessToken: accessToken });
|
||||||
@ -276,43 +244,27 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
|
|||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
User.findOne({ google: profile.id }, function(err, existingUser) {
|
User.findOne({ google: 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 Google manually from Account Settings.' });
|
user.email = profile._json.email;
|
||||||
//done(err);
|
user.google = profile.id;
|
||||||
var user = existingEmailUser;
|
user.tokens.push({ kind: 'google', accessToken: accessToken });
|
||||||
user.email = profile._json.email;
|
user.profile.name = user.profile.name || profile.displayName;
|
||||||
user.google = profile.id;
|
user.profile.gender = user.profile.gender || profile._json.gender;
|
||||||
user.tokens.push({ kind: 'google', accessToken: accessToken });
|
user.profile.picture = user.profile.picture || profile._json.picture;
|
||||||
user.profile.name = profile.displayName;
|
user.save(function(err) {
|
||||||
user.profile.gender = profile._json.gender;
|
done(err, user);
|
||||||
user.profile.picture = profile._json.picture;
|
});
|
||||||
user.save(function(err) {
|
|
||||||
done(err, user);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var user = new User();
|
|
||||||
user.email = profile._json.email;
|
|
||||||
user.google = profile.id;
|
|
||||||
user.tokens.push({ kind: 'google', accessToken: accessToken });
|
|
||||||
user.profile.name = profile.displayName;
|
|
||||||
user.profile.gender = profile._json.gender;
|
|
||||||
user.profile.picture = profile._json.picture;
|
|
||||||
user.save(function(err) {
|
|
||||||
done(err, user);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
// Login Required middleware.
|
// Login Required middleware.
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Reference in New Issue
Block a user