Browse Source

Updated the email system to store information for captcha and email in the new configuration system.

pull/33/head
jrtechs 6 years ago
parent
commit
779401f326
3 changed files with 27 additions and 13 deletions
  1. +7
    -1
      config.json
  2. +14
    -11
      includes/contact.js
  3. +6
    -1
      utils/configLoader.js

+ 7
- 1
config.json View File

@ -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"
}

+ 14
- 11
includes/contact.js View File

@ -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

+ 6
- 1
utils/configLoader.js View File

@ -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");

Loading…
Cancel
Save