freeCodeCamp/controllers/contact.js

35 lines
913 B
JavaScript
Raw Normal View History

var config = require('../config/config.json');
var sendgrid = require('sendgrid')(config.sendgrid.user, config.sendgrid.password);
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,
success: req.flash('success'),
error: req.flash('error')
2013-11-20 04:19:53 +00:00
});
};
exports.postContact = function(req, res) {
var firstName = req.body.firstName;
var lastName = req.body.lastName;
var email = req.body.email;
var body = req.body.contactBody;
var sendTo = 'sakhat@gmail.com';
var subject = 'API Example | Contact Form';
sendgrid.send({
to: sendTo,
from: email,
subject: subject,
text: body
}, function(err, json) {
if (err) {
req.flash('error', err.message);
return res.redirect('/contact');
}
req.flash('success', 'Email has been sent successfully!');
res.redirect('/contact');
});
};