2014-12-23 16:48:28 +00:00
|
|
|
var nodemailer = require('nodemailer'),
|
|
|
|
debug = require('debug')('freecc:cntr:contact'),
|
|
|
|
secrets = require('../config/secrets');
|
|
|
|
|
2014-07-15 21:24:28 +00:00
|
|
|
var transporter = nodemailer.createTransport({
|
2014-10-12 08:51:55 +00:00
|
|
|
service: 'Mandrill',
|
2014-02-11 15:46:39 +00:00
|
|
|
auth: {
|
2014-10-12 08:51:55 +00:00
|
|
|
user: secrets.mandrill.user,
|
|
|
|
pass: secrets.mandrill.password
|
2014-02-11 15:46:39 +00:00
|
|
|
}
|
2014-02-10 21:32:38 +00:00
|
|
|
});
|
2013-11-30 18:14:29 +00:00
|
|
|
|
2013-12-20 18:48:33 +00:00
|
|
|
/**
|
|
|
|
* GET /contact
|
2014-01-07 23:15:14 +00:00
|
|
|
* Contact form page.
|
2013-12-20 18:48:33 +00:00
|
|
|
*/
|
2014-01-13 09:34:54 +00:00
|
|
|
|
2013-11-19 19:33:11 +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
|
|
|
});
|
2013-11-19 19:33:11 +00:00
|
|
|
};
|
|
|
|
|
2013-12-20 18:48:33 +00:00
|
|
|
/**
|
|
|
|
* POST /contact
|
2014-02-10 21:32:38 +00:00
|
|
|
* Send a contact form via Nodemailer.
|
2013-12-20 18:48:33 +00:00
|
|
|
*/
|
2014-01-13 09:24:31 +00:00
|
|
|
|
2013-11-19 19:33:11 +00:00
|
|
|
exports.postContact = function(req, res) {
|
2014-01-24 03:19:18 +00: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 16:48:28 +00:00
|
|
|
if (req.validationErrors()) {
|
2014-01-24 03:19:18 +00:00
|
|
|
req.flash('errors', errors);
|
2014-10-26 16:32:57 +00:00
|
|
|
return res.redirect('/nonprofits');
|
2014-01-24 03:19:18 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 21:32:38 +00:00
|
|
|
var mailOptions = {
|
2014-12-23 16:48:28 +00:00
|
|
|
to: 'team@freecodecamp.com',
|
|
|
|
name: req.body.name,
|
|
|
|
from: req.body.email,
|
2014-12-31 17:57:48 +00:00
|
|
|
subject: 'CodeNonprofit Project Idea from ' + req.body.name,
|
2014-12-23 16:48:28 +00:00
|
|
|
text: req.body.message
|
2014-02-10 21:32:38 +00:00
|
|
|
};
|
2013-11-30 18:34:28 +00:00
|
|
|
|
2014-07-15 21:24:28 +00:00
|
|
|
transporter.sendMail(mailOptions, function(err) {
|
2013-11-30 18:27:43 +00:00
|
|
|
if (err) {
|
2014-01-24 03:36:28 +00:00
|
|
|
req.flash('errors', { msg: err.message });
|
2014-10-26 16:32:57 +00:00
|
|
|
return res.redirect('/nonprofits');
|
2013-11-30 18:27:43 +00:00
|
|
|
}
|
2014-01-28 22:44:25 +00:00
|
|
|
req.flash('success', { msg: 'Email has been sent successfully!' });
|
2014-10-26 16:32:57 +00:00
|
|
|
res.redirect('/nonprofits');
|
2013-11-30 18:14:29 +00:00
|
|
|
});
|
2013-12-20 18:48:33 +00:00
|
|
|
};
|