diff options
| author | Adam Soltys <[email protected]> | 2016-09-22 10:11:45 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2016-09-22 10:11:45 -0700 |
| commit | 62e3ba927a918d012bb6af0e034866db880454e0 (patch) | |
| tree | 5614d2b68a094cad9b4bb15c1f9606e9626ef128 /routes | |
| parent | 9634031d5972051da76dab048d748d96e56b2715 (diff) | |
| parent | acd47767d0c02dfa1a4152208a16c21255e4943b (diff) | |
| download | coinos-server-62e3ba927a918d012bb6af0e034866db880454e0.tar.gz coinos-server-62e3ba927a918d012bb6af0e034866db880454e0.zip | |
Merge branch 'notifications'
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/transactions.js | 35 | ||||
| -rw-r--r-- | routes/users.js | 42 |
2 files changed, 60 insertions, 17 deletions
diff --git a/routes/transactions.js b/routes/transactions.js index 759ec14a..d132e418 100644 --- a/routes/transactions.js +++ b/routes/transactions.js @@ -1,8 +1,12 @@ (function() { - var db; + var config, db, moment; db = require('../redis'); + config = require("../config"); + + moment = require('moment'); + module.exports = { index: function(req, res) { return res.render('transactions/index', { @@ -53,6 +57,35 @@ create: function(req, res) { var finish; finish = function() { + db.hgetall("user:" + req.params.user.toLowerCase(), function(err, user) { + return res.render('transactions/notification', { + layout: 'mail', + amount: (req.body.received * req.body.exchange).toFixed(2).toString() + ' ' + user.currency, + address: req.body.address, + txid: req.body.txid, + js: (function() { + return global.js; + }), + css: (function() { + return global.css; + }) + }, function(err, html) { + var content, from_email, helper, mail, request, sg, subject, to_email; + helper = require('sendgrid').mail; + from_email = new helper.Email('[email protected]'); + to_email = new helper.Email(user.email); + subject = 'Transaction Sent'; + content = new helper.Content('text/html', html); + mail = new helper.Mail(from_email, subject, to_email, content); + sg = require('sendgrid')(config.sendgrid_token); + request = sg.emptyRequest({ + method: 'POST', + path: '/v3/mail/send', + body: mail.toJSON() + }); + return sg.API(request); + }); + }); res.write(JSON.stringify(req.body)); return res.end(); }; diff --git a/routes/users.js b/routes/users.js index 1449eb02..2c79cb31 100644 --- a/routes/users.js +++ b/routes/users.js @@ -154,15 +154,20 @@ 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: '[email protected]', - subject: 'Welcome to CoinOS', - html: html + var content, from_email, helper, mail, sg, subject, to_email; + helper = require('sendgrid').mail; + from_email = new helper.Email('[email protected]'); + to_email = new helper.Email(req.body.email); + subject = 'Welcome to CoinOS'; + content = new helper.Content('text/html', html); + mail = new helper.Mail(from_email, subject, to_email, content); + sg = require('sendgrid')(config.sendgrid_token); + request = sg.emptyRequest({ + method: 'POST', + path: '/v3/mail/send', + body: mail.toJSON() }); - return sendgrid.send(email); + return sg.API(request); }); }); }); @@ -232,15 +237,20 @@ 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: '[email protected]', - subject: 'CoinOS Wallet Key', - html: html + var content, from_email, helper, mail, sg, subject, to_email; + helper = require('sendgrid').mail; + from_email = new helper.Email('[email protected]'); + to_email = new helper.Email(req.body.email); + subject = 'CoinOS Wallet Key'; + content = new helper.Content('text/html', html); + mail = new helper.Mail(from_email, subject, to_email, content); + sg = require('sendgrid')(config.sendgrid_token); + request = sg.emptyRequest({ + method: 'POST', + path: '/v3/mail/send', + body: mail.toJSON() }); - return sendgrid.send(email); + return sg.API(request); }); } }, |
