From 5797c03250d0b0283172d76658b475280538379b Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 21 Jul 2012 12:17:54 +0200 Subject: [PATCH] moved sensitive data in environment variables --- app.js | 8 ++++---- config.json | 21 ++++++++++----------- lib/email/mailer.js | 31 ++++++++++++++----------------- package.json | 15 ++++++++------- routes/user.js | 1 - 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/app.js b/app.js index 48fec1c..9ef114a 100644 --- a/app.js +++ b/app.js @@ -14,8 +14,8 @@ var config = require('./config') * Setting up redis. */ -var songsdb = redisurl.createClient(config.songsdburl) - , usersdb = redisurl.createClient(config.usersdburl); +var songsdb = redisurl.createClient(process.env.SONGS_DB_URL) + , usersdb = redisurl.createClient(process.env.USERS_DB_URL); songsdb.on('error', function(err) { console.log(err.message); @@ -36,7 +36,7 @@ app.use(express.static(__dirname + '/public'), {maxAge: 2592000000}); app.use(express.favicon(__dirname + '/public/static/images/favicon.ico', {maxAge: 2592000000})); app.use(express.bodyParser()); app.use(express.cookieParser()); -app.use(express.session({secret:config.sessionsecret,store:sessionstore})); +app.use(express.session({secret:process.env.SESSION_SECRET,store:sessionstore})); app.set('view engine', 'jade'); app.set('view options', {layout:false}); @@ -56,7 +56,7 @@ app.dynamicHelpers({ // Routes site.use({db:songsdb,rooms:config.rooms}); -user.use({db:usersdb,rooms:config.rooms,sendgrid:config.sendgrid}); +user.use({db:usersdb,rooms:config.rooms}); app.get('/', site.index); app.get('/artworks', site.artworks); diff --git a/config.json b/config.json index 827a469..107551e 100644 --- a/config.json +++ b/config.json @@ -1,14 +1,13 @@ { - "port": 80, - "songsdburl": "", - "usersdburl": "", - "sessionsecret": "", - "sendgrid": { - "user": "", - "pass": "" - }, - "songsinarun": 15, - "gameswithnorepeats": 3, "allowederrors": 2, - "rooms": ["pop", "rock", "rap", "80s", "mixed"] + "gameswithnorepeats": 3, + "port": 8138, + "rooms": [ + "pop", + "rock", + "rap", + "80s", + "mixed" + ], + "songsinarun": 15 } diff --git a/lib/email/mailer.js b/lib/email/mailer.js index 516ef30..a1e67b6 100644 --- a/lib/email/mailer.js +++ b/lib/email/mailer.js @@ -6,9 +6,8 @@ var fs = require('fs') , jade = require('jade') , nodemailer = require('nodemailer') , jadetemplate = fs.readFileSync(__dirname + '/template.jade') - , texttemplate = fs.readFileSync(__dirname + '/template.txt', 'utf-8') - , transport; - + , texttemplate = fs.readFileSync(__dirname + '/template.txt', 'utf-8'); + /** * Generate the HTML version of the message. */ @@ -23,6 +22,18 @@ var plaintextMessage = function(token) { return texttemplate.replace(//, token); }; +/** + * Create a reusable transport method. + */ + +var transport = nodemailer.createTransport('SMTP', { + service: 'SendGrid', + auth: { + user: process.env.SENDGRID_USER, + pass: process.env.SENDGRID_PASS + } +}); + /** * Send the reset password email. */ @@ -41,17 +52,3 @@ exports.sendEmail = function(to, token, callback) { callback(null, response); }); }; - -/** - * Create a reusable transport method. - */ - -exports.setTransport = function(sendgrid) { - transport = nodemailer.createTransport ('SMTP', { - service: 'SendGrid', - auth: { - user: sendgrid.user, - pass: sendgrid.pass - } - }); -}; diff --git a/package.json b/package.json index 9f044e5..4af33bd 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { - "name": "binb", "dependencies": { "async": "0.1.x", "canvas": "0.12.x", @@ -8,15 +7,17 @@ "express": "2.5.x", "jade": "0.26.x", "nodemailer": "0.3.x", + "redis": "0.7.x", "redis-url": "0.1.x", "socket.io": "0.9.x" }, - "subdomain": "binb", - "scripts": { - "start": "app.js" - }, "engines": { "node": "0.6.x" }, - "version": "0.3.2" -} + "name": "binb", + "scripts": { + "start": "app.js" + }, + "subdomain": "binb", + "version": "0.3.2-16" +} \ No newline at end of file diff --git a/routes/user.js b/routes/user.js index 42da220..f357eb8 100644 --- a/routes/user.js +++ b/routes/user.js @@ -78,7 +78,6 @@ var buildLeaderboards = function(pointsresults, timesresults) { exports.use = function(options) { db = options.db; rooms = options.rooms; - mailer.setTransport(options.sendgrid); // Populate the whitelist of follow-up URLs followupurls.push('/'); followupurls.push('/changepasswd'); -- 2.54.0