diff options
| author | Adam Soltys <[email protected]> | 2014-09-15 10:09:03 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-09-15 10:09:03 -0700 |
| commit | 0765adfc8993e8641e61a8db40965ef091c0f451 (patch) | |
| tree | 3acbb32a40e47f295dec6b2085ef0f15213baaac /routes | |
| parent | d07a4738359e1825e3629871b96c049275ab18c0 (diff) | |
| download | coinos-server-0765adfc8993e8641e61a8db40965ef091c0f451.tar.gz coinos-server-0765adfc8993e8641e61a8db40965ef091c0f451.zip | |
Mail key
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/users.js | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/routes/users.js b/routes/users.js index 47562df4..df89eb5b 100644 --- a/routes/users.js +++ b/routes/users.js @@ -114,14 +114,19 @@ }); }); return require('crypto').randomBytes(48, function(ex, buf) { - var token, url; + var host, token, url; token = buf.toString('base64').replace(/\//g, '').replace(/\+/g, ''); - db.set(token, req.body.username); + db.set("token:" + token, req.body.username); + host = req.hostname; + if (host === 'localhost') { + host += ':3000'; + } url = "" + req.protocol + "://" + req.hostname + ":3000/verify/" + token; return res.render('users/welcome', { user: req.params.user, layout: 'mail', url: url, + privkey: req.body.privkey, js: (function() { return global.js; }), @@ -172,7 +177,7 @@ if (req.body.password === '') { delete req.body.password; } - return db.hmset("user:" + req.params.user, req.body, function() { + db.hmset("user:" + req.params.user, req.body, function() { if (req.body.password != null) { return bcrypt.hash(req.body.password, 12, function(err, hash) { return db.hmset("user:" + req.params.user, { @@ -185,11 +190,34 @@ return res.redirect("/" + req.params.user); } }); + if ((req.body.privkey != null) && req.body.privkey !== '' && req.body.email !== '') { + return res.render('users/key', { + user: req.params.user, + layout: 'mail', + key: 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: '[email protected]', + subject: 'CoinOS Wallet Key', + html: html + }); + return sendgrid.send(email); + }); + } }, verify: function(req, res) { - return db.get(req.params.token, function(err, reply) { + return db.get("token:" + req.params.token, function(err, reply) { if (err || !reply) { - res.write('Invalid token'); + res.write("Invalid Verification Token"); return res.end(); } else { return db.hset("user:" + (reply.toString()), "verified", "true", function() { |
