From 779401f32624c50c868755c11867dcf7e1f5cb9b Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sun, 25 Nov 2018 17:20:21 -0500 Subject: [PATCH] Updated the email system to store information for captcha and email in the new configuration system. --- config.json | 8 +++++++- includes/contact.js | 25 ++++++++++++++----------- utils/configLoader.js | 7 ++++++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/config.json b/config.json index 0e37fb7..a9f33ed 100644 --- a/config.json +++ b/config.json @@ -6,5 +6,11 @@ "SQL_HOST": "sql-hostname", "SQL_DATABASE": "sql-database-name", "SQL_USER": "sql-user", - "SQL_PASSWORD": "sql-password" + "SQL_PASSWORD": "sql-password", + + + "CAPTCHA_SECRET": "captcha-secret", + "GMAIL_ACCOUNT": "email@gmail.com", + "EMAIL_PASSWORD": "email-password", + "DESTINATION_EMAIL": "destination email address" } \ No newline at end of file diff --git a/includes/contact.js b/includes/contact.js index f78c4ef..9c2e154 100644 --- a/includes/contact.js +++ b/includes/contact.js @@ -6,33 +6,36 @@ * @author Jeffery Russell 8-19-18 */ -//used for file IO +/** used for file IO */ const utils = require('../utils/utils.js'); -//used for static files +/** used for static files */ const includes = require('../includes/includes'); -//for parsing post data +/** for parsing post data */ const qs = require('querystring'); -//cleans form submission +/** cleans form submission */ const sanitizer = require('sanitizer'); -//used to send post data for the captcha +/** used to send post data for the captcha */ const Request = require('request'); -//sends the email using a throw away gmail account +/** sends the email using a throw away gmail account */ const nodemailer = require("nodemailer"); -//agent for sending the email +/** agent for sending the email */ const smtpTransport = require('nodemailer-smtp-transport'); +/** Used to load the config file from the disk */ +const config = require('../utils/configLoader').getConfig(); + //captcha secret -const CAPTCHA_SECRET = utils.getFileLine("../captcha_secret"); +const CAPTCHA_SECRET = config.CAPTCHA_SECRET; //password to gmail account -const EMAIL_PASSWORD = utils.getFileLine("../email_password"); +const EMAIL_PASSWORD = config.EMAIL_PASSWORD; /** @@ -92,14 +95,14 @@ const sendEmail = function(name, email, message) service: 'gmail', host: 'smtp.gmail.com', auth: { - user: 'jrtechswebsite@gmail.com', + user: config.GMAIL_ACCOUNT, pass: EMAIL_PASSWORD } })); const mailOptions = { - to: "jeffery@jrtechs.net", // list of receivers + to: config.DESTINATION_EMAIL, // list of receivers subject: "Jrtechs.net form submission", // Subject line text: message, // plaintext body html: message diff --git a/utils/configLoader.js b/utils/configLoader.js index db2d3ca..8f5d960 100644 --- a/utils/configLoader.js +++ b/utils/configLoader.js @@ -10,13 +10,18 @@ module.exports= { /** + * Verifies the contents of the config file + * and returns it. If the config is incomplete, + * it terminates the program. * * @returns {*|any} */ getConfig: function() { const configContents = ["PORT", "SESSION_SECRET", - "SQL_HOST", "SQL_DATABASE", "SQL_PASSWORD"]; + "SQL_HOST", "SQL_DATABASE", "SQL_PASSWORD", + "CAPTCHA_SECRET", "GMAIL_ACCOUNT", "EMAIL_PASSWORD", + "DESTINATION_EMAIL"]; var config = utils.getFileAsJSON("./config.json");