From 80be8a9a09865e91ff36d37ae3bfa0450d5ca286 Mon Sep 17 00:00:00 2001 From: joates Date: Fri, 19 Sep 2014 03:07:50 +0100 Subject: [PATCH] added SMTP transport module --- .gitignore | 3 +- html/assets/js/email.js | 177 ---------------------------------------- package.json | 1 + server.js | 26 +++++- 4 files changed, 27 insertions(+), 180 deletions(-) delete mode 100644 html/assets/js/email.js diff --git a/.gitignore b/.gitignore index a303d01..47472fc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ results npm-debug.log node_modules -html/assets/js/email.js +html/assets/js/email* + diff --git a/html/assets/js/email.js b/html/assets/js/email.js deleted file mode 100644 index 50927e1..0000000 --- a/html/assets/js/email.js +++ /dev/null @@ -1,177 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - var fn = queue.shift(); - fn(); - } - } - }, true); - - return function nextTick(fn) { - queue.push(fn); - window.postMessage('process-tick', '*'); - }; - } - - return function nextTick(fn) { - setTimeout(fn, 0); - }; -})(); - -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -} - -// TODO(shtylman) -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; - -},{}],2:[function(require,module,exports){ -/*! - * domready (c) Dustin Diaz 2014 - License MIT - */ -!function (name, definition) { - - if (typeof module != 'undefined') module.exports = definition() - else if (typeof define == 'function' && typeof define.amd == 'object') define(definition) - else this[name] = definition() - -}('domready', function () { - - var fns = [], listener - , doc = document - , hack = doc.documentElement.doScroll - , domContentLoaded = 'DOMContentLoaded' - , loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState) - - - if (!loaded) - doc.addEventListener(domContentLoaded, listener = function () { - doc.removeEventListener(domContentLoaded, listener) - loaded = 1 - while (listener = fns.shift()) listener() - }) - - return function (fn) { - loaded ? fn() : fns.push(fn) - } - -}); - -},{}],3:[function(require,module,exports){ -module.exports = require('./lib/valid-email'); -},{"./lib/valid-email":4}],4:[function(require,module,exports){ -/*! - * Valid Email - * Copyright(c) 2013 John Henry - * MIT Licensed - */ - -/** - * Valid-Email: - * - * An alternative to using a regular expression to validate email. - * Inspired by: - * http://stackoverflow.com/questions/997078/email-regular-expression - * http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address - * - * Examples: - * console.log(require('valid-email')('john@iamjohnhenry.com'))//#true - * console.log(require('valid-email')('iamjohnhenry.com'))//#false - * - * @param {String} email - * // potential email address - * @return {Boolean} - * @api public - */ -module.exports = function valid(email){ - var at = email.search("@"); - if (at <0) return false; - var user = email.substr(0, at); - var domain = email.substr(at+1); - var userLen = user.length; - var domainLen = domain.length; - if (userLen < 1 || userLen > 64) return false;// user part length exceeded - if (domainLen < 1 || domainLen > 255) return false;// domain part length exceeded - if (user.charAt(0) === '.' || user.charAt(userLen-1) === '.') return false;// user part starts or ends with '.' - if (user.match(/\.\./)) return false;// user part has two consecutive dots - if (!domain.match(/^[A-Za-z0-9.-]+$/)) return false;// character not valid in domain part - if (domain.match( /\\.\\./)) return false;// domain part has two consecutive dots - if (!user.replace("\\\\","").match(/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/)) if (!user.replace("\\\\","").match(/^"(\\\\"|[^"])+"$/)) return false - return true; -} -},{}],5:[function(require,module,exports){ -(function (process){ -var ready = require('domready') - , check_email = require('valid-email') - -process.nextTick(function() { - ready(function() { - - var form = document.getElementById('signup-form') - , input_email = '' - - for (var n = 0, l = form.childNodes.length; n < l; n++) { - var el = form.childNodes[n] -console.dir(el) - if (el.nodeName === 'INPUT' && el.name === 'email') - input_email = el.nodeValue - } - - document - .getElementById("signup-form") - .addEventListener("click", function() { - if (input_email) { - var is_valid = check_email(input_email) - if (is_valid) { - alert('got it, thanks '+ input_email) - form.submit() - } else { - input_email = '' - alert("that doesn't look like an email address, please try again...") - } - } - }) - }) -}) - - -}).call(this,require('_process')) -},{"_process":1,"domready":2,"valid-email":3}]},{},[5]); diff --git a/package.json b/package.json index 747d3d0..2d34516 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "browserify": "^5.11.2", "domready": "^1.0.7", + "nodemailer": "^1.3.0", "valid-email": "0.0.1" } } diff --git a/server.js b/server.js index a0bebd8..9de12a9 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,8 @@ #!/usr/bin/env node -var server = require('http').createServer(handler) +var nodemailer = require('nodemailer') + , transporter = nodemailer.createTransport() + , server = require('http').createServer(handler) , fs = require('fs') , re = new RegExp('\.js$', 'i') , port = process.env.PORT || /*80*/ 8000 @@ -14,8 +16,28 @@ function handler(req, res) { if (/^\/email\?/.test(req.url)) { var params = require('url').parse(req.url, true) - if (params && params.query.email) // @TODO: validate input + if (params && params.query.email) { + + /* + var opts = { + from: 'news-mailer@squatconf.eu', + to: params.query.email, + subject: "Hello, everyone is welcome at SquatConf..", + text: 'Please verify that you wish to signup by following this link\n' + + '[##> link here <##]\n\n' + + 'You can ignore this message if you DID NOT request to signup at our website\n' + + 'http://squatconf.eu\n\n' + + 'next event is in Paris, we hope to see you there !!\n' + + 'kind regards from the team,\nSquatConf Paris 2014' + } + transporter.sendMail(opts, function(err, data) { + if (err) return console.error('email problem !', err) + console.log('email sent', data) + }) + */ + console.log('got email:', params.query) + } res.statusCode = 302 res.setHeader('Location', '/') return res.end()