From 5ca3eff6c28b346de1126fe328b365eecee2552e Mon Sep 17 00:00:00 2001 From: Ian Webster Date: Sat, 3 Jan 2015 14:48:45 -0500 Subject: [PATCH] Hash phone number sent to authbox and don't crash w no authbox config --- package.json | 2 +- server/app.js | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 03743bd..296d393 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,10 @@ "express": "~3.5.1" , "authbox": "^0.9.2" , "jade": "~0.14.2" + , "mixpanel": "~0.0.19" , "nodemailer": "~0.6.1" , "redis-url": "~0.2.0" , "underscore": "~1.6.0" - , "mixpanel": "~0.0.19" } , "devDependencies": { } diff --git a/server/app.js b/server/app.js index a880323..40f1674 100644 --- a/server/app.js +++ b/server/app.js @@ -1,15 +1,23 @@ var express = require('express') , app = express() - , authbox = require('authbox') , _ = require('underscore') + , authbox = require('authbox') + , crypto = require('crypto') + , exec = require('child_process').exec , fs = require('fs') , mixpanel = require('mixpanel') - , exec = require('child_process').exec - , spawn = require('child_process').spawn - , Stream = require('stream') , redis = require('redis-url').connect() + , spawn = require('child_process').spawn , text = require('../lib/text'); +// Express config +app.set('views', __dirname + '/views'); +app.set('view engine', 'jade'); + +app.use(express.cookieParser()); +app.use(express.static(__dirname + '/public')); +app.use(express.bodyParser()); + // Enable log messages when sending texts. text.debug(true); @@ -34,6 +42,7 @@ try { try { authbox_config = require('./authbox_config.js'); authbox.configure(authbox_config); + app.use(authbox.middleware); } catch(e) { authbox = {log: function() {}}; } @@ -48,15 +57,6 @@ try { access_keys = {}; } -// Express config -app.set('views', __dirname + '/views'); -app.set('view engine', 'jade'); - -app.use(express.cookieParser()); -app.use(express.static(__dirname + '/public')); -app.use(authbox.middleware); -app.use(express.bodyParser()); - // App routes app.get('/', function(req, res) { fs.readFile(__dirname + '/views/index.html', 'utf8', function(err, text){ @@ -103,12 +103,14 @@ function textRequestHandler(req, res, number, region, key) { var message = req.body.message; if (message.indexOf(':') > -1) { // Handle problem with vtext where message would not get sent properly if it - // contains a colon + // contains a colon. message = ' ' + message; } + shasum.update(number); + var authbox_digest = shasum.digest('hex'); _.extend(authbox_details, { - recipient__phone: number, + recipient: number, message__text: message });