forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor passport so that emails aren't fired if there are errors in …
…save actions
- Loading branch information
Michael Q Larson
committed
Mar 31, 2015
1 parent
22507de
commit a60c5eb
Showing
3 changed files
with
49 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r | |
User.findOne({ facebook: profile.id }, function(err, existingUser) { | ||
if (existingUser) return done(null, existingUser); | ||
User.findOne({ email: profile._json.email }, function(err, existingEmailUser) { | ||
if (err) { return done(err); } | ||
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(); | ||
|
@@ -96,29 +97,29 @@ passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, r | |
user.profile.location = (profile._json.location) ? profile._json.location.name : ''; | ||
user.save(function(err) { | ||
done(err, user); | ||
}); | ||
var transporter = nodemailer.createTransport({ | ||
service: 'Mandrill', | ||
auth: { | ||
user: secrets.mandrill.user, | ||
pass: secrets.mandrill.password | ||
} | ||
}); | ||
var mailOptions = { | ||
to: user.email, | ||
from: '[email protected]', | ||
subject: 'Welcome to Free Code Camp!', | ||
text: [ | ||
'Greetings from San Francisco!\n\n', | ||
'Thank you for joining our community.\n', | ||
'Feel free to email us at this address if you have any questions about Free Code Camp.\n', | ||
"And if you have a moment, check out our blog: blog.freecodecamp.com.\n", | ||
'Good luck with the challenges!\n\n', | ||
'- Our All-Volunteer Team' | ||
].join('') | ||
}; | ||
transporter.sendMail(mailOptions, function(err) { | ||
if (err) { return err; } | ||
var transporter = nodemailer.createTransport({ | ||
service: 'Mandrill', | ||
auth: { | ||
user: secrets.mandrill.user, | ||
pass: secrets.mandrill.password | ||
} | ||
}); | ||
var mailOptions = { | ||
to: user.email, | ||
from: '[email protected]', | ||
subject: 'Welcome to Free Code Camp!', | ||
text: [ | ||
'Greetings from San Francisco!\n\n', | ||
'Thank you for joining our community.\n', | ||
'Feel free to email us at this address if you have any questions about Free Code Camp.\n', | ||
"And if you have a moment, check out our blog: blog.freecodecamp.com.\n", | ||
'Good luck with the challenges!\n\n', | ||
'- Our All-Volunteer Team' | ||
].join('') | ||
}; | ||
transporter.sendMail(mailOptions, function(err) { | ||
if (err) { return err; } | ||
}); | ||
}); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,34 +153,34 @@ exports.postEmailSignup = function(req, res, next) { | |
|
||
user.save(function(err) { | ||
if (err) { return next(err); } | ||
var transporter = nodemailer.createTransport({ | ||
service: 'Mandrill', | ||
auth: { | ||
user: secrets.mandrill.user, | ||
pass: secrets.mandrill.password | ||
} | ||
}); | ||
var mailOptions = { | ||
to: user.email, | ||
from: '[email protected]', | ||
subject: 'Welcome to Free Code Camp!', | ||
text: [ | ||
'Greetings from San Francisco!\n\n', | ||
'Thank you for joining our community.\n', | ||
'Feel free to email us at this address if you have any questions about Free Code Camp.\n', | ||
"And if you have a moment, check out our blog: blog.freecodecamp.com.\n", | ||
'Good luck with the challenges!\n\n', | ||
'- Our All-Volunteer Team' | ||
].join('') | ||
}; | ||
transporter.sendMail(mailOptions, function(err) { | ||
if (err) { return err; } | ||
}); | ||
req.logIn(user, function(err) { | ||
if (err) { return next(err); } | ||
res.redirect('/email-signup'); | ||
}); | ||
}); | ||
var transporter = nodemailer.createTransport({ | ||
service: 'Mandrill', | ||
auth: { | ||
user: secrets.mandrill.user, | ||
pass: secrets.mandrill.password | ||
} | ||
}); | ||
var mailOptions = { | ||
to: user.email, | ||
from: '[email protected]', | ||
subject: 'Welcome to Free Code Camp!', | ||
text: [ | ||
'Greetings from San Francisco!\n\n', | ||
'Thank you for joining our community.\n', | ||
'Feel free to email us at this address if you have any questions about Free Code Camp.\n', | ||
"And if you have a moment, check out our blog: blog.freecodecamp.com.\n", | ||
'Good luck with the challenges!\n\n', | ||
'- the Volunteer Camp Counselor Team' | ||
].join('') | ||
}; | ||
transporter.sendMail(mailOptions, function(err) { | ||
if (err) { return err; } | ||
}); | ||
}); | ||
}); | ||
}; | ||
|