From 4dbc0706f296d9ea179666fe96c066f7cade1ceb Mon Sep 17 00:00:00 2001 From: joates Date: Mon, 22 Sep 2014 07:18:17 +0100 Subject: [PATCH] v0.4.1-rc2 [don't use join() in ecstatic.opts] --- package.json | 2 +- server.js | 9 ++++----- src/email-confirm.js | 5 ++--- src/email-submit.js | 19 +++++++++++-------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 2aee1ff..a9785bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "squatconf-web", - "version": "0.4.0", + "version": "0.4.1", "description": "website for the squatConf conference", "main": "server.js", "scripts": { diff --git a/server.js b/server.js index 425747a..d933990 100644 --- a/server.js +++ b/server.js @@ -5,14 +5,13 @@ var fs = require('fs') , stack = require('stack') , route = require('tiny-route') , assets = require('ecstatic') - , join = require('path').join , config = require('./config') , db = require('level')(config.db_path, config.db_opts) , port = process.env.PORT || config.port // create the level db folder if it does not exists -if(!fs.existsSync('./db/squatconf')){ - fs.mkdirSync('./db/squatconf', 0766, function(err){ +if(!fs.existsSync(config.db_path)){ + fs.mkdirSync(config.db_path, 0766, function(err){ if(err){ console.log(err); } @@ -22,7 +21,7 @@ if(!fs.existsSync('./db/squatconf')){ var app = stack( route('/email', require('./src/email-submit')(db)) , route('/confirm', require('./src/email-confirm')(db)) - , assets(join(__dirname, 'html')) + , assets({ root: __dirname +'/html', handleError: false }) ) process.on('uncaughtException', function (err) { @@ -31,7 +30,7 @@ process.on('uncaughtException', function (err) { }) http.createServer(app).listen(port, function() { - console.log('['+ process.pid +'] server started on port '+ port) + console.log('[PID='+ process.pid +'] server started on port '+ port) console.log('(use Ctrl+c to stop the server)') }) diff --git a/src/email-confirm.js b/src/email-confirm.js index a2e5df9..eaba7de 100644 --- a/src/email-confirm.js +++ b/src/email-confirm.js @@ -8,13 +8,12 @@ module.exports = function(db) { var params = require('url').parse(req.url, true) if (params && params.query.email && params.query.token) { - //console.log('got token:', params.query) var email = sanitize(params.query.email) , token = sanitize(params.query.token) db.get(email, function(err, obj) { - if (err) next(err) + if (err) return console.error(err) // db read OK.. if (obj && obj.token === token) { @@ -22,7 +21,7 @@ module.exports = function(db) { obj.trace = obj.trace.concat(ip(req)) db.put(email, obj, function(err) { - if (err) next(err) + if (err) return console.error(err) // db write OK.. res.statusCode = 302 diff --git a/src/email-submit.js b/src/email-submit.js index 4b45b69..781ffa5 100644 --- a/src/email-submit.js +++ b/src/email-submit.js @@ -10,18 +10,19 @@ module.exports = function(db) { var params = require('url').parse(req.url, true) if (params && params.query.email) { - console.log('got email:', params.query) var obj = {} , email = sanitize(params.query.email) + console.log('got email:', params.query) + obj.token = rn() obj.verified = false obj.events = { paris: params.query.paris ? true : false } obj.trace = ip(req) db.put(email, obj, function(err) { - if (err) next(err) + if (err) return console.error(err) // db write OK.. var nodemailer = require('nodemailer') @@ -33,18 +34,20 @@ module.exports = function(db) { from : config.email.from , to : email , subject: config.email.subject + //, link : link , text : config.email.bodyText.replace(/\%link\%/, link) } transporter.sendMail(opts, function(err, data) { - if (err) throw err + if (err) return console.error(err) + // validation email sent - console.log('email sent..', data) - }) + console.log('email sent..', opts) - res.statusCode = 302 - res.setHeader('Location', '/') - return res.end() + res.statusCode = 302 + res.setHeader('Location', '/') + return res.end() + }) }) }