2013-12-20 01:31:16 -05:00
|
|
|
var secrets = require('../config/secrets');
|
2014-02-10 13:32:38 -08:00
|
|
|
var nodemailer = require("nodemailer");
|
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-01-28 17:44:25 -05:00
|
|
|
title: 'Contact'
|
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.
|
2014-02-07 10:21:18 -05:00
|
|
|
* @param email
|
|
|
|
* @param name
|
|
|
|
* @param message
|
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();
|
|
|
|
|
|
|
|
var errors = req.validationErrors();
|
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
req.flash('errors', errors);
|
2014-10-26 09:22:53 -07:00
|
|
|
return res.redirect('/non-profits');
|
2014-01-23 22:19:18 -05:00
|
|
|
}
|
|
|
|
|
2013-11-30 13:34:28 -05:00
|
|
|
var from = req.body.email;
|
2013-12-04 20:55:01 -05:00
|
|
|
var name = req.body.name;
|
2014-01-13 04:24:31 -05:00
|
|
|
var body = req.body.message;
|
2014-10-26 09:22:53 -07:00
|
|
|
var to = 'michaelqlarson@gmail.com';
|
2014-10-12 01:51:55 -07:00
|
|
|
var subject = 'Free Code Camp';
|
2013-11-30 13:27:43 -05:00
|
|
|
|
2014-02-10 13:32:38 -08:00
|
|
|
var mailOptions = {
|
2014-01-13 04:34:54 -05:00
|
|
|
to: to,
|
2013-12-20 13:48:33 -05:00
|
|
|
from: from,
|
|
|
|
subject: subject,
|
2014-03-16 13:46:08 -04:00
|
|
|
text: body
|
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:22:53 -07:00
|
|
|
return res.redirect('/non-profits');
|
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:22:53 -07:00
|
|
|
res.redirect('/non-profits');
|
2013-11-30 13:14:29 -05:00
|
|
|
});
|
2013-12-20 13:48:33 -05:00
|
|
|
};
|