aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2016-09-22 10:11:19 -0700
committerAdam Soltys <[email protected]>2016-09-22 10:11:24 -0700
commitacd47767d0c02dfa1a4152208a16c21255e4943b (patch)
tree5614d2b68a094cad9b4bb15c1f9606e9626ef128
parent515b1a63871af43fca536f0a1dd653dcaa1d2ba9 (diff)
downloadcoinos-server-acd47767d0c02dfa1a4152208a16c21255e4943b.tar.gz
coinos-server-acd47767d0c02dfa1a4152208a16c21255e4943b.zip
Upgrade sendgrid and fill in transaction details in notification email
-rw-r--r--package.json2
-rw-r--r--public/js/profile.coffee1
-rw-r--r--public/js/profile.js1
-rw-r--r--routes/transactions.js54
-rw-r--r--routes/users.js42
-rw-r--r--src/routes/transactions.coffee45
-rw-r--r--src/routes/users.coffee39
-rw-r--r--views/transactions/notification.html2
-rw-r--r--views/users/profile.html5
9 files changed, 116 insertions, 75 deletions
diff --git a/package.json b/package.json
index 0f94d4b8..ec334a23 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,7 @@
"passport-local": "1.0.0",
"redis": "0.11.0",
"request": "~2.40.0",
- "sendgrid": "~1.2.0"
+ "sendgrid": "^4.3.0"
},
"devDependencies": {
"coffeeify": "^1.2.0",
diff --git a/public/js/profile.coffee b/public/js/profile.coffee
index dda0597c..fdbde8ee 100644
--- a/public/js/profile.coffee
+++ b/public/js/profile.coffee
@@ -7,7 +7,6 @@ $(->
user = $('#username').val()
$.getJSON("/#{user}.json", (data) ->
- $('#username').val(data.username)
$('#email').val(data.email)
$('#profile').fadeIn()
)
diff --git a/public/js/profile.js b/public/js/profile.js
index d680e209..a49c7583 100644
--- a/public/js/profile.js
+++ b/public/js/profile.js
@@ -12,7 +12,6 @@
$('#title').focus();
user = $('#username').val();
$.getJSON("/" + user + ".json", function(data) {
- $('#username').val(data.username);
$('#email').val(data.email);
return $('#profile').fadeIn();
});
diff --git a/routes/transactions.js b/routes/transactions.js
index 31875918..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();
};
@@ -62,25 +95,6 @@
if (result) {
return finish();
}
- res.render('notification', {
- layout: 'mail',
- 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({
- subject: 'Transaction Sent',
- html: html
- });
- return sendgrid.send(email);
- });
multi = db.multi();
multi.hmset(req.body.txid, req.body);
multi.rpush("" + req.params.user + ":transactions", req.body.txid);
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,
- 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,
- 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);
});
}
},
diff --git a/src/routes/transactions.coffee b/src/routes/transactions.coffee
index cadb73b1..696eefba 100644
--- a/src/routes/transactions.coffee
+++ b/src/routes/transactions.coffee
@@ -1,4 +1,6 @@
db = require('../redis')
+config = require("../config")
+moment = require('moment')
module.exports =
index: (req, res) ->
@@ -39,6 +41,32 @@ module.exports =
create: (req, res) ->
finish = ->
+ db.hgetall("user:"+req.params.user.toLowerCase(), (err, user) ->
+ 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: (-> global.js)
+ css: (-> global.css)
+ (err, html) ->
+ 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()
+ )
+
+ sg.API(request)
+ )
+ )
res.write(JSON.stringify(req.body))
res.end()
@@ -46,23 +74,6 @@ module.exports =
db.exists(req.body.txid, (err, result) ->
return finish() if result
- res.render('notification',
- layout: 'mail',
- js: (-> global.js),
- css: (-> global.css),
- (err, html) ->
- sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password)
-
- email = new sendgrid.Email(
- subject: 'Transaction Sent'
- html: html
- )
-
- sendgrid.send(email)
- )
-
multi = db.multi()
multi.hmset(req.body.txid, req.body)
multi.rpush("#{req.params.user}:transactions", req.body.txid)
diff --git a/src/routes/users.coffee b/src/routes/users.coffee
index e682602b..d1c8f602 100644
--- a/src/routes/users.coffee
+++ b/src/routes/users.coffee
@@ -112,16 +112,22 @@ module.exports = (sessions) ->
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
+ 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()
)
- sendgrid.send(email)
+ sg.API(request)
)
)
)
@@ -178,16 +184,21 @@ module.exports = (sessions) ->
js: (-> global.js),
css: (-> global.css),
(err, html) ->
- sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password)
+ 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)
- email = new sendgrid.Email(
- to: req.body.email
- subject: 'CoinOS Wallet Key'
- html: html
+ sg = require('sendgrid')(config.sendgrid_token)
+ request = sg.emptyRequest(
+ method: 'POST'
+ path: '/v3/mail/send'
+ body: mail.toJSON()
)
- sendgrid.send(email)
+ sg.API(request)
)
verify: (req, res) ->
diff --git a/views/transactions/notification.html b/views/transactions/notification.html
index 49a045a7..5f066cf8 100644
--- a/views/transactions/notification.html
+++ b/views/transactions/notification.html
@@ -1,3 +1,3 @@
<h1>Transaction Received</h1>
-You got paid
+You received {{amount}} from {{address}}. Visit <a href="https://blockchain.info/tx/{{txid}}">https://blockchain.info/tx/{{txid}}</a> for more details.
diff --git a/views/users/profile.html b/views/users/profile.html
index 70f9acfc..0f37d20e 100644
--- a/views/users/profile.html
+++ b/views/users/profile.html
@@ -5,10 +5,7 @@
<form id="profile" action="/{{user}}" method="post" style="display: none">
<h1>Account Profile</h1>
- <div class="form-group">
- <label for="username">Username:</label>
- <input type="text" id="username" name="username" value="{{user}}" class="form-control" />
- </div>
+ <input type="hidden" id="username" name="username" value="{{user}}" class="form-control" />
<div class="form-group">
<label for="email">Email:</label>