From b9b9701a05209271d4a2cad9d9c3374bd575c8d9 Mon Sep 17 00:00:00 2001 From: joates Date: Mon, 12 Jan 2015 20:38:49 +0000 Subject: [PATCH] src/* deprecated --- src/email-client.js | 56 ------------------------------ src/email-confirm.js | 48 -------------------------- src/email-submit.js | 81 -------------------------------------------- src/ip-trace.js | 8 ----- src/mail.js | 0 src/rng.js | 20 ----------- 6 files changed, 213 deletions(-) delete mode 100644 src/email-client.js delete mode 100644 src/email-confirm.js delete mode 100644 src/email-submit.js delete mode 100644 src/ip-trace.js delete mode 100644 src/mail.js delete mode 100644 src/rng.js diff --git a/src/email-client.js b/src/email-client.js deleted file mode 100644 index efa385f..0000000 --- a/src/email-client.js +++ /dev/null @@ -1,56 +0,0 @@ -var ready = require('domready') - , check_email = require('valid-email') - , loadsvg = require('load-svg') - -process.nextTick(function() { - ready(function() { - - var form = document.getElementById('signup-form') - , input_email = '' - , status_msg = document.getElementById('status-msg') - , logoCont = document.getElementById('logoCont') - - loadsvg('/assets/img/squatconf_baguette.svg', function (err, svg) { - logoCont.appendChild(svg); - }); - - for (var n = 0, l = form.childNodes[1].childNodes.length; n < l; n++) { - var el = form.childNodes[1].childNodes[n] - if (el.nodeName === 'INPUT' && el.name === 'email') - input_email = el - } - - document - .getElementById("signup-form") - .addEventListener("click", function(e) { - if (e.srcElement.nodeName === 'BUTTON') { - if (input_email && input_email.value) { - var is_valid = check_email(input_email.value) - if (is_valid) { - var progress = 0 - , timerID = null - e.preventDefault() - status_msg.className = 'info' - status_msg.innerHTML = "Sending" - timerID = setInterval(function() { - if (++progress < 8) { - status_msg.innerHTML += "." - } else { - clearInterval(timerID) - form.submit() - } - }, 150) - } else { - e.preventDefault() - input_email.value = '' - status_msg.className = 'error' - status_msg.innerHTML = "that doesn't look like an email address," - + "
please try again..." - setTimeout(function() { status_msg.innerHTML = ' ' }, 2000) - } - } - } - }) - }) -}) - diff --git a/src/email-confirm.js b/src/email-confirm.js deleted file mode 100644 index 17f6cd1..0000000 --- a/src/email-confirm.js +++ /dev/null @@ -1,48 +0,0 @@ -var sanitize = require('xss-escape') - , ip = require('./ip-trace') - -module.exports = function(db) { - return function (req, res, next) { - req.resume() - - function error(e) { - console.error(e) - return next(e || e.msg || 'ERROR') - } - - var params = require('url').parse(req.url, true) - - if (params && params.query.email && params.query.token) { - - var email = sanitize(params.query.email) - , token = sanitize(params.query.token) - - db.get(email, function(err, obj) { - if (err) return error(err) - - // db read OK.. - if (obj && ! obj.verified) { - if (obj.token === token) { - obj.verified = true - obj.trace = obj.trace.concat(ip(req)) - - db.put(email, obj, function(err) { - if (err) return error(err) - - // db write OK.. - res.statusCode = 302 - res.setHeader('Location', '/verified.html') - return res.end() - }) - } - } else { - error('email is already verified: '+ email) - } - }) - - } else { - error('invalid input: '+ JSON.stringify(params.query)) - } - } -} - diff --git a/src/email-submit.js b/src/email-submit.js deleted file mode 100644 index 3c8d133..0000000 --- a/src/email-submit.js +++ /dev/null @@ -1,81 +0,0 @@ -var sanitize = require('xss-escape') - , rn = require('./rng') - , ip = require('./ip-trace') - , config = require('../config') - , Mailgun = require('mailgun').Mailgun - , mg = new Mailgun(config.mailjetKey); - - - - -module.exports = function(db) { - return function (req, res, next) { - req.resume() - - function error(e) { - console.error(e) - return next(e || e.msg || 'ERROR') - } - - var params = require('url').parse(req.url, true) - - if (params && params.query.email) { - - var obj = {} - , email = sanitize(params.query.email) - - 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) - - // db write OK.. - var url = config.host +'/confirm' - , qstr = '?email='+ email +'&token='+ obj.token - , link = url + qstr +'\n\n' - , opts = { - from : config.email.from - , to : email - , subject: config.email.subject - , text : config.email.bodyText.replace(/\%link\%/, link) - } - - mg.sendText( - opts.from - , email - , opts.subject - , opts.text - , {} - , function(err) { - if (err) console.log('Guru meditation: ' + err); - else{ - res.statusCode = 302 - res.setHeader('Location', '/') - console.log('email sent..', opts)} - return res.end() - }); - - - - - }) - - } else { - error('already verified: '+ email) - } - }) - - } else { - error('invalid input: '+ JSON.stringify(params.query)) - } - } -} - diff --git a/src/ip-trace.js b/src/ip-trace.js deleted file mode 100644 index f34bbe0..0000000 --- a/src/ip-trace.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function(req) { - if (req.headers['x-forwarded-for']) { - return req.headers['x-forwarded-for'].split(',') - } else { - return [ req.connection.remoteAddress ] - } -} - diff --git a/src/mail.js b/src/mail.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/rng.js b/src/rng.js deleted file mode 100644 index d3e8684..0000000 --- a/src/rng.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = function() { - var crypto = require('crypto') - - function rng_Base64(len) { - return crypto.randomBytes(Math.ceil(len * 3 / 4)) - .toString('base64') - .slice(0, len) - .replace(/\+/g, '0') - .replace(/\//g, '0') - } - - return [ rng_Base64(8) - , rng_Base64(4) - , rng_Base64(4) - , rng_Base64(4) - , rng_Base64(12) - ] - .join('-') -} -