|
|
@ -1,34 +1,47 @@ |
|
|
|
/** |
|
|
|
* File which sends emails to me from |
|
|
|
* a captcha protected form on the contact |
|
|
|
* page. |
|
|
|
* |
|
|
|
* @author Jeffery Russell 8-19-18 |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
//used for file IO
|
|
|
|
const utils = require('../utils/utils.js'); |
|
|
|
|
|
|
|
|
|
|
|
//used for static files
|
|
|
|
const includes = require('../includes/includes'); |
|
|
|
|
|
|
|
//for parsing post data
|
|
|
|
const qs = require('querystring'); |
|
|
|
|
|
|
|
//cleans form submission
|
|
|
|
const sanitizer = require('sanitizer'); |
|
|
|
|
|
|
|
//used to send post data for the captcha
|
|
|
|
const Request = require('request'); |
|
|
|
|
|
|
|
|
|
|
|
//sends the email using a throw away gmail account
|
|
|
|
const nodemailer = require("nodemailer"); |
|
|
|
|
|
|
|
|
|
|
|
//agent for sending the email
|
|
|
|
const smtpTransport = require('nodemailer-smtp-transport'); |
|
|
|
|
|
|
|
|
|
|
|
//captcha secret
|
|
|
|
const CAPTCHA_SECRET = utils.getFileLine("../captcha_secret"); |
|
|
|
|
|
|
|
//password to gmail account
|
|
|
|
const EMAIL_PASSWORD = utils.getFileLine("../email_password"); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Verifies if the captcha response recieved from the post data was |
|
|
|
* valid, or are bots trying to get around the captcha |
|
|
|
* |
|
|
|
* @param data captcha data from post request |
|
|
|
* @returns {Promise} resolves whether the captcha is valid |
|
|
|
*/ |
|
|
|
const verifyCapcha = function(data) |
|
|
|
{ |
|
|
|
const recaptcha_url = "https://www.google.com/recaptcha/api/siteverify?" + |
|
|
@ -64,7 +77,14 @@ const verifyCapcha = function(data) |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Sends a email to my personal emaail address using a throw away |
|
|
|
* gmail account |
|
|
|
* |
|
|
|
* @param name from contact form |
|
|
|
* @param email from contact form |
|
|
|
* @param message from contact form |
|
|
|
*/ |
|
|
|
const sendEmail = function(name, email, message) |
|
|
|
{ |
|
|
|
|
|
|
@ -103,7 +123,14 @@ const sendEmail = function(name, email, message) |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* If there was post data on the contact page, it processes it to see |
|
|
|
* if it was a valid captcha request and sends an email. If no post data was sent, |
|
|
|
* the normal form is displayed |
|
|
|
* |
|
|
|
* @param request -- main express request |
|
|
|
* @returns {Promise} renders the html of the contact widget |
|
|
|
*/ |
|
|
|
const processContactPage = function(request) |
|
|
|
{ |
|
|
|
return new Promise(function(resolve, reject) |
|
|
@ -144,6 +171,15 @@ const processContactPage = function(request) |
|
|
|
|
|
|
|
module.exports = |
|
|
|
{ |
|
|
|
/** |
|
|
|
* Displays the contact page along with the header, sidebar, and footer. |
|
|
|
* This uses the admin header because it doesn't need any minified css |
|
|
|
* which has been purged of some css classes which are not used in any |
|
|
|
* of the blog posts. |
|
|
|
* |
|
|
|
* @param request -- main express request |
|
|
|
* @param result -- renders the html of the contact page |
|
|
|
*/ |
|
|
|
main: function(request, result) |
|
|
|
{ |
|
|
|
result.writeHead(200, {'Content-Type': 'text/html'}); |
|
|
|