2014-12-23 08:48:28 -08:00
|
|
|
var nodemailer = require('nodemailer'),
|
|
|
|
debug = require('debug')('freecc:cntr:contact'),
|
|
|
|
secrets = require('../config/secrets');
|
|
|
|
|
2014-07-15 17:24:28 -04:00
|
|
|
var transporter = nodemailer.createTransport({
|
2014-10-12 01:51:55 -07:00
|
|
|
service: 'Mandrill',
|
2014-02-11 10:46:39 -05:00
|
|
|
auth: {
|
2014-10-12 01:51:55 -07:00
|
|
|
user: secrets.mandrill.user,
|
|
|
|
pass: secrets.mandrill.password
|
2014-02-11 10:46:39 -05:00
|
|
|
}
|
2014-02-10 13:32:38 -08:00
|
|
|
});
|
2013-11-30 13:14:29 -05:00
|
|
|
|
2013-12-20 13:48:33 -05:00
|
|
|
/**
|
|
|
|
* GET /contact
|
2014-01-07 18:15:14 -05:00
|
|
|
* Contact form page.
|
2013-12-20 13:48:33 -05:00
|
|
|
*/
|
2014-01-13 04:34:54 -05:00
|
|
|
|
2013-11-19 14:33:11 -05:00
|
|
|
exports.getContact = function(req, res) {
|
2013-11-19 23:19:53 -05:00
|
|
|
res.render('contact', {
|
2014-11-23 15:08:46 -06:00
|
|
|
title: 'Free Code Work for Nonprofits Project Submission Page'
|
2013-11-19 23:19:53 -05:00
|
|
|
});
|
2013-11-19 14:33:11 -05:00
|
|
|
};
|
|
|
|
|
2013-12-20 13:48:33 -05:00
|
|
|
/**
|
|
|
|
* POST /contact
|
2014-02-10 13:32:38 -08:00
|
|
|
* Send a contact form via Nodemailer.
|
2013-12-20 13:48:33 -05:00
|
|
|
*/
|
2014-01-13 04:24:31 -05:00
|
|
|
|
2013-11-19 14:33:11 -05:00
|
|
|
exports.postContact = function(req, res) {
|
2014-01-23 22:19:18 -05:00
|
|
|
req.assert('name', 'Name cannot be blank').notEmpty();
|
|
|
|
req.assert('email', 'Email is not valid').isEmail();
|
|
|
|
req.assert('message', 'Message cannot be blank').notEmpty();
|
|
|
|
|
2014-12-23 08:48:28 -08:00
|
|
|
if (req.validationErrors()) {
|
2014-01-23 22:19:18 -05:00
|
|
|
req.flash('errors', errors);
|
2014-10-26 09:32:57 -07:00
|
|
|
return res.redirect('/nonprofits');
|
2014-01-23 22:19:18 -05:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:32:38 -08:00
|
|
|
var mailOptions = {
|
2014-12-23 08:48:28 -08:00
|
|
|
to: 'team@freecodecamp.com',
|
|
|
|
name: req.body.name,
|
|
|
|
from: req.body.email,
|
2014-12-31 09:57:48 -08:00
|
|
|
subject: 'CodeNonprofit Project Idea from ' + req.body.name,
|
2014-12-23 08:48:28 -08:00
|
|
|
text: req.body.message
|
2014-02-10 13:32:38 -08:00
|
|
|
};
|
2013-11-30 13:34:28 -05:00
|
|
|
|
2014-07-15 17:24:28 -04:00
|
|
|
transporter.sendMail(mailOptions, function(err) {
|
2013-11-30 13:27:43 -05:00
|
|
|
if (err) {
|
2014-01-23 22:36:28 -05:00
|
|
|
req.flash('errors', { msg: err.message });
|
2014-10-26 09:32:57 -07:00
|
|
|
return res.redirect('/nonprofits');
|
2013-11-30 13:27:43 -05:00
|
|
|
}
|
2014-01-28 17:44:25 -05:00
|
|
|
req.flash('success', { msg: 'Email has been sent successfully!' });
|
2014-10-26 09:32:57 -07:00
|
|
|
res.redirect('/nonprofits');
|
2013-11-30 13:14:29 -05:00
|
|
|
});
|
2013-12-20 13:48:33 -05:00
|
|
|
};
|