2013-12-07 01:18:21 +00:00
|
|
|
var config = require('../config/config');
|
2013-11-30 18:14:29 +00:00
|
|
|
var sendgrid = require('sendgrid')(config.sendgrid.user, config.sendgrid.password);
|
|
|
|
|
2013-11-19 19:33:11 +00:00
|
|
|
exports.getContact = function(req, res) {
|
2013-11-20 04:19:53 +00:00
|
|
|
res.render('contact', {
|
|
|
|
title: 'Contact',
|
2013-11-20 13:03:10 +00:00
|
|
|
user: req.user,
|
2013-11-30 18:27:43 +00:00
|
|
|
success: req.flash('success'),
|
|
|
|
error: req.flash('error')
|
2013-11-20 04:19:53 +00:00
|
|
|
});
|
2013-11-19 19:33:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.postContact = function(req, res) {
|
2013-11-30 18:34:28 +00:00
|
|
|
var from = req.body.email;
|
2013-12-05 01:55:01 +00:00
|
|
|
var name = req.body.name;
|
2013-11-30 07:30:00 +00:00
|
|
|
var body = req.body.contactBody;
|
2013-11-30 18:14:29 +00:00
|
|
|
|
2013-11-30 18:27:43 +00:00
|
|
|
var sendTo = 'sakhat@gmail.com';
|
|
|
|
var subject = 'API Example | Contact Form';
|
|
|
|
|
2013-11-30 18:34:28 +00:00
|
|
|
var email = new sendgrid.Email({
|
2013-11-30 18:27:43 +00:00
|
|
|
to: sendTo,
|
2013-11-30 18:34:28 +00:00
|
|
|
from: from,
|
2013-11-30 18:27:43 +00:00
|
|
|
subject: subject,
|
|
|
|
text: body
|
2013-11-30 18:34:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
sendgrid.send(email, function(err) {
|
2013-11-30 18:27:43 +00:00
|
|
|
if (err) {
|
|
|
|
req.flash('error', err.message);
|
|
|
|
return res.redirect('/contact');
|
|
|
|
}
|
|
|
|
req.flash('success', 'Email has been sent successfully!');
|
|
|
|
res.redirect('/contact');
|
2013-11-30 18:14:29 +00:00
|
|
|
});
|
2013-11-19 19:33:11 +00:00
|
|
|
};
|