Add email functionality to done-with-first-100-hours page and refactor nonprofit link to be on same controller in same view folder

This commit is contained in:
Michael Q Larson
2015-01-14 13:28:20 -08:00
parent 89357f3d13
commit 13faedc86e
8 changed files with 108 additions and 63 deletions

View File

@@ -10,46 +10,65 @@ var transporter = nodemailer.createTransport({
}
});
/**
* GET /contact
* Contact form page.
*/
module.exports = {
/**
* GET /contact
* Contact form page.
*/
exports.getContact = function(req, res) {
res.render('contact', {
title: 'Free Code Work for Nonprofits Project Submission Page'
});
};
getNonprofitsForm: function(req, res) {
res.render('contact/nonprofits', {
title: 'Free Code Work for Nonprofits Project Submission Page'
});
},
/**
* POST /contact
* Send a contact form via Nodemailer.
*/
/**
* POST /contact
* Send a contact form via Nodemailer.
*/
exports.postContact = function(req, res) {
req.assert('name', 'Name cannot be blank').notEmpty();
req.assert('email', 'Email is not valid').isEmail();
req.assert('message', 'Message cannot be blank').notEmpty();
postNonprofitsForm: function(req, res) {
var mailOptions = {
to: 'team@freecodecamp.com',
name: req.body.name,
from: req.body.email,
subject: 'CodeNonprofit Project Idea from ' + req.body.name,
text: req.body.message
};
if (req.validationErrors()) {
req.flash('errors', errors);
return res.redirect('/nonprofits');
transporter.sendMail(mailOptions, function (err) {
if (err) {
req.flash('errors', {msg: err.message});
return res.redirect('/nonprofits');
}
req.flash('success', {msg: 'Email has been sent successfully!'});
res.redirect('/nonprofits');
});
},
getDoneWithFirst100Hours: function(req, res) {
res.render('contact/done-with-first-100-hours', {
title:
'Congratulations on finishing the first 100 hours of Free Code Camp!'
});
},
postDoneWithFirst100Hours: function(req, res) {
var mailOptions = {
to: 'team@freecodecamp.com',
name: 'Completionist',
from: req.body.email,
subject: 'Code Camper at ' + req.body.email + ' has completed the first 100 hours',
text: ''
};
transporter.sendMail(mailOptions, function (err) {
if (err) {
req.flash('errors', {msg: err.message});
return res.redirect('/done-with-first-100-hours');
}
req.flash('success', {msg: 'Email has been sent successfully!'});
res.redirect('/');
});
}
var mailOptions = {
to: 'team@freecodecamp.com',
name: req.body.name,
from: req.body.email,
subject: 'CodeNonprofit Project Idea from ' + req.body.name,
text: req.body.message
};
transporter.sendMail(mailOptions, function(err) {
if (err) {
req.flash('errors', { msg: err.message });
return res.redirect('/nonprofits');
}
req.flash('success', { msg: 'Email has been sent successfully!' });
res.redirect('/nonprofits');
});
};