aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2015-01-03 12:03:59 -0800
committerAdam Soltys <[email protected]>2015-01-03 12:03:59 -0800
commit15ee6390c1831199da840d63c25edeacff1daebe (patch)
tree4ff6237285f135abe2ab50f5fb9c2b33860bb916
parent0575689747b2868205ceb48ead622032ebe173fe (diff)
downloadcoinos-server-15ee6390c1831199da840d63c25edeacff1daebe.tar.gz
coinos-server-15ee6390c1831199da840d63c25edeacff1daebe.zip
Only send mail in production
-rw-r--r--routes/users.js64
-rw-r--r--src/routes/users.coffee52
2 files changed, 61 insertions, 55 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,
- 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,
+ 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}"
+ 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)
+ 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
- subject: 'Welcome to CoinOS'
- html: html
- )
+ email = new sendgrid.Email(
+ to: req.body.email
+ subject: 'Welcome to CoinOS'
+ html: html
+ )
- sendgrid.send(email)
+ 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',