From 81b30afabd1736e3dec4bb05c377b2d28317c2fe Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 11 Nov 2012 21:57:11 -0800 Subject: Save calculator params to database --- app.coffee | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'app.coffee') diff --git a/app.coffee b/app.coffee index 2cda19f2..d5d4c21c 100644 --- a/app.coffee +++ b/app.coffee @@ -10,6 +10,11 @@ app.set('view engine', 'html') app.set('views', __dirname + '/views') app.use(express.static(__dirname + '/public')) app.use(require('connect-assets')(src: 'public')) +app.use(express.bodyParser()); +app.use((err, req, res, next) -> + res.status(500) + res.render('error', error: err ) +) app.get('/', (req, res) -> res.render('index', js: (-> global.js), css: (-> global.css)) @@ -44,9 +49,12 @@ app.get('/transactions/:login', (req, res) -> ) app.get('/ticker', (req, res) -> + symbol = req.params.symbol + symbol or= 'virtexCAD' + options = host: 'bitcoincharts.com', - path: '/t/depthcalc.json?symbol=virtexCAD&type=bid&amount=1000¤cy=true' + path: '/t/depthcalc.json?symbol=' + symbol + '&type=bid&amount=1000¤cy=true' require('http').get(options, (r) -> r.setEncoding('utf-8') @@ -56,6 +64,28 @@ app.get('/ticker', (req, res) -> ) ) +app.post('/create', (req, res) -> + connection = require('mysql').createConnection(config.database) + + connection.connect() + connection.query(""" + INSERT INTO users + (login, name, address, commission) + VALUES + (?, ?, ?, ?) + """, + [ + req.body.login, + req.body.name, + req.body.address, + req.body.commission + ], (err, rows) -> + connection.end() + res.writeHead(302, 'Location': '/' + req.body.login) + res.end() + ) +) + app.get('/:client', (req, res) -> res.render('calculator', client: req.params.client, -- cgit v1.2.3