diff options
| author | Adam Soltys <[email protected]> | 2012-11-21 11:10:55 +0400 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-11-21 11:10:55 +0400 |
| commit | d63fd390890174a4f734fb13ed9cbd500fe004ca (patch) | |
| tree | 019a9291b28b5c616820ec02b8aa8880b8ecc4de /app.coffee | |
| parent | abe11c9bf0a38435d782a3d2ebcd2743b7c302a2 (diff) | |
| download | coinos-server-d63fd390890174a4f734fb13ed9cbd500fe004ca.tar.gz coinos-server-d63fd390890174a4f734fb13ed9cbd500fe004ca.zip | |
Revert "No bcrypt"
This reverts commit 86918fe5eee925a1a1eb0b836e177b247c0700b9.
Diffstat (limited to 'app.coffee')
| -rw-r--r-- | app.coffee | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -3,6 +3,7 @@ http = require('http') path = require('path') engines = require('consolidate') passport = require('passport') +bcrypt = require('bcrypt') config = require('./config') app = express() @@ -44,6 +45,14 @@ app.get('/', (req, res) -> res.render('index', js: (-> global.js), css: (-> global.css)) ) +app.get('/bcrypt', (req, res) -> + salt = "$2a$10$3R8tUtIoU/fllQD9zEgTZe" + hash = bcrypt.hashSync("chelsea", salt) + res.write(salt + "\n") + res.write(hash) + res.end() +) + app.get('/:user/report', (req, res) -> res.render('report', user: req.params.user, @@ -119,6 +128,31 @@ app.post('/login', (req, res, next) -> )(req, res, next) ) +app.post('/users', (req, res) -> + if req.body.login + if req.body.password + bcrypt.hash(req.body.password, 12, (err, hash) -> + db = require("redis").createClient() + db.hget(req.body.login, 'password', (err, password) -> + bcrypt.compare(req.body.password, password, (err, match) -> + if match + req.body.password = password + db.hmset(req.body.login, req.body, -> + res.redirect(req.body.login) + ) + else + res.redirect(req.body.login) + ) + ) + ) + else + params = [] + for k,v of req.body + params.push(encodeURIComponent(k), '=', encodeURIComponent(v), '&') + params.pop() if (params.length) + res.redirect('calculator?' + params.join('')) +) + app.post('/:user/transactions', (req, res) -> user = req.params.user db = require("redis").createClient() |
