From 15ee6390c1831199da840d63c25edeacff1daebe Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 3 Jan 2015 12:03:59 -0800 Subject: Only send mail in production --- routes/users.js | 64 +++++++++++++++++++++++++------------------------ src/routes/users.coffee | 58 +++++++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 58 deletions(-) diff --git a/routes/users.js b/routes/users.js index 46a8f8f8..c5e0f0ee 100644 --- a/routes/users.js +++ b/routes/users.js @@ -113,38 +113,40 @@ return sessions.create(req, res); }); }); - return require('crypto').randomBytes(48, function(ex, buf) { - var host, token, url; - token = buf.toString('base64').replace(/\//g, '').replace(/\+/g, ''); - db.set("token:" + token, req.body.username); - host = req.hostname; - if (host === 'localhost') { - host += ':3000'; - } - url = "" + req.protocol + "://" + host + "/verify/" + token; - return res.render('users/welcome', { - user: req.params.user, - layout: 'mail', - url: url, - privkey: req.body.privkey, - js: (function() { - return global.js; - }), - css: (function() { - return global.css; - }) - }, function(err, html) { - var email, sendgrid; - sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password); - email = new sendgrid.Email({ - to: req.body.email, - from: 'adam@coinos.io', - subject: 'Welcome to CoinOS', - html: html + if (process.env.NODE_ENV === 'production') { + return require('crypto').randomBytes(48, function(ex, buf) { + var host, token, url; + token = buf.toString('base64').replace(/\//g, '').replace(/\+/g, ''); + db.set("token:" + token, req.body.username); + host = req.hostname; + if (host === 'localhost') { + host += ':3000'; + } + url = "" + req.protocol + "://" + host + "/verify/" + token; + return res.render('users/welcome', { + user: req.params.user, + layout: 'mail', + url: url, + privkey: req.body.privkey, + js: (function() { + return global.js; + }), + css: (function() { + return global.css; + }) + }, function(err, html) { + var email, sendgrid; + sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password); + email = new sendgrid.Email({ + to: req.body.email, + from: 'adam@coinos.io', + subject: 'Welcome to CoinOS', + html: html + }); + return sendgrid.send(email); }); - return sendgrid.send(email); }); - }); + } }); }, edit: function(req, res) { @@ -193,7 +195,7 @@ return res.redirect("/" + req.params.user); } }); - if ((req.body.privkey != null) && req.body.privkey !== '' && req.body.email !== '') { + if (process.env.NODE_ENV === 'production' && (req.body.privkey != null) && req.body.privkey !== '' && req.body.email !== '') { return res.render('users/key', { user: req.params.user, layout: 'mail', diff --git a/src/routes/users.coffee b/src/routes/users.coffee index 838ef631..d3ecabaf 100644 --- a/src/routes/users.coffee +++ b/src/routes/users.coffee @@ -83,33 +83,34 @@ module.exports = (sessions) -> ) ) - require('crypto').randomBytes(48, (ex, buf) -> - token = buf.toString('base64').replace(/\//g,'').replace(/\+/g,'') - db.set("token:#{token}", req.body.username) - host = req.hostname - host += ':3000' if host is 'localhost' - url = "#{req.protocol}://#{host}/verify/#{token}" - - res.render('users/welcome', - user: req.params.user, - layout: 'mail', - url: url, - privkey: req.body.privkey, - js: (-> global.js), - css: (-> global.css), - (err, html) -> - sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password) - - email = new sendgrid.Email( - to: req.body.email - from: 'adam@coinos.io' - subject: 'Welcome to CoinOS' - html: html - ) - - sendgrid.send(email) + if process.env.NODE_ENV is 'production' + require('crypto').randomBytes(48, (ex, buf) -> + token = buf.toString('base64').replace(/\//g,'').replace(/\+/g,'') + db.set("token:#{token}", req.body.username) + host = req.hostname + host += ':3000' if host is 'localhost' + url = "#{req.protocol}://#{host}/verify/#{token}" + + res.render('users/welcome', + user: req.params.user, + layout: 'mail', + url: url, + privkey: req.body.privkey, + js: (-> global.js), + css: (-> global.css), + (err, html) -> + sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password) + + email = new sendgrid.Email( + to: req.body.email + from: 'adam@coinos.io' + subject: 'Welcome to CoinOS' + html: html + ) + + sendgrid.send(email) + ) ) - ) ) edit: (req, res) -> @@ -148,7 +149,10 @@ module.exports = (sessions) -> res.redirect("/#{req.params.user}") ) - if req.body.privkey? and req.body.privkey != '' and req.body.email != '' + if process.env.NODE_ENV is 'production' and + req.body.privkey? and + req.body.privkey != '' and + req.body.email != '' res.render('users/key', user: req.params.user, layout: 'mail', -- cgit v1.2.3