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 /src | |
| parent | d07a4738359e1825e3629871b96c049275ab18c0 (diff) | |
| download | coinos-server-0765adfc8993e8641e61a8db40965ef091c0f451.tar.gz coinos-server-0765adfc8993e8641e61a8db40965ef091c0f451.zip | |
Mail key
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/users.coffee | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/routes/users.coffee b/src/routes/users.coffee index dc22303d..e5a26af2 100644 --- a/src/routes/users.coffee +++ b/src/routes/users.coffee @@ -85,13 +85,16 @@ module.exports = (sessions) -> require('crypto').randomBytes(48, (ex, buf) -> token = buf.toString('base64').replace(/\//g,'').replace(/\+/g,'') - db.set(token, req.body.username) + db.set("token:#{token}", req.body.username) + host = req.hostname + host += ':3000' if host is 'localhost' url = "#{req.protocol}://#{req.hostname}:3000/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) -> @@ -130,6 +133,7 @@ module.exports = (sessions) -> update: (req, res) -> if req.body.password is '' delete req.body.password + db.hmset("user:"+req.params.user, req.body, -> if req.body.password? bcrypt.hash(req.body.password, 12, (err, hash) -> @@ -141,10 +145,30 @@ module.exports = (sessions) -> res.redirect("/#{req.params.user}") ) + if req.body.privkey? and req.body.privkey != '' and req.body.email != '' + res.render('users/key', + user: req.params.user, + layout: 'mail', + key: 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: '[email protected]' + subject: 'CoinOS Wallet Key' + html: html + ) + + sendgrid.send(email) + ) + verify: (req, res) -> - db.get(req.params.token, (err, reply) -> + db.get("token:#{req.params.token}", (err, reply) -> if err or !reply - res.write('Invalid token') + res.write("Invalid Verification Token") res.end() else db.hset("user:#{reply.toString()}", "verified", "true", -> |
