diff options
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() |
