From baeab714db54230ce287b6f04ec0716549bc6b97 Mon Sep 17 00:00:00 2001 From: joates Date: Mon, 22 Sep 2014 22:16:59 +0100 Subject: [PATCH] ignore email signups that already exist and are verified, fixes #9 --- src/email-submit.js | 71 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/email-submit.js b/src/email-submit.js index 211459f..6504360 100644 --- a/src/email-submit.js +++ b/src/email-submit.js @@ -19,42 +19,47 @@ module.exports = function(db) { 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) return error(err) - - // db write OK.. - var nodemailer = require('nodemailer') - , transporter = nodemailer.createTransport() - , url = config.host +'/confirm' - , qstr = '?email='+ email +'&token='+ obj.token - , link = url + qstr +'\n\n' - - var opts = { - from : config.email.from - , to : email - , subject: config.email.subject - //, link : link - , text : config.email.bodyText.replace(/\%link\%/, link) - } + db.get(email, function(err, value) { + if ((err && err.type == 'NotFoundError') || ! value.verified) { + + 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) return error(err) - transporter.sendMail(opts, function(err, data) { - if (err) return error(err) + // db write OK.. + var nodemailer = require('nodemailer') + , transporter = nodemailer.createTransport() + , url = config.host +'/confirm' + , qstr = '?email='+ email +'&token='+ obj.token + , link = url + qstr +'\n\n' - // validation email sent - console.log('email sent..', opts) + var opts = { + from : config.email.from + , to : email + , subject: config.email.subject + , text : config.email.bodyText.replace(/\%link\%/, link) + } + + transporter.sendMail(opts, function(err, data) { + if (err) return error(err) + + // validation email sent + console.log('email sent..', opts) + + res.statusCode = 302 + res.setHeader('Location', '/') + return res.end() + }) + }) + } + } - res.statusCode = 302 - res.setHeader('Location', '/') - return res.end() - }) - }) } else { error('invalid input: '+ JSON.stringify(params.query)) }