freeCodeCamp/controllers/contact.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

var nodemailer = require('nodemailer'),
debug = require('debug')('freecc:cntr:contact'),
secrets = require('../config/secrets');
var transporter = nodemailer.createTransport({
service: 'Mandrill',
auth: {
user: secrets.mandrill.user,
pass: secrets.mandrill.password
}
});
/**
* GET /contact
2014-01-07 23:15:14 +00:00
* Contact form page.
*/
2014-01-13 09:34:54 +00:00
exports.getContact = function(req, res) {
2013-11-20 04:19:53 +00:00
res.render('contact', {
2014-11-23 21:08:46 +00:00
title: 'Free Code Work for Nonprofits Project Submission Page'
2013-11-20 04:19:53 +00:00
});
};
/**
* 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();
if (req.validationErrors()) {
req.flash('errors', errors);
2014-10-26 16:32:57 +00:00
return res.redirect('/nonprofits');
}
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 });
2014-10-26 16:32:57 +00:00
return res.redirect('/nonprofits');
}
req.flash('success', { msg: 'Email has been sent successfully!' });
2014-10-26 16:32:57 +00:00
res.redirect('/nonprofits');
});
};