aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2012-11-11 21:57:11 -0800
committerAdam Soltys <[email protected]>2012-11-11 21:57:11 -0800
commit81b30afabd1736e3dec4bb05c377b2d28317c2fe (patch)
treedd71cb80284d29be0e635f95025e46f24b1fb94b
parent3e900e0bba211c2bbf2bb10c85a82dd9ce6943f0 (diff)
downloadcoinos-server-81b30afabd1736e3dec4bb05c377b2d28317c2fe.tar.gz
coinos-server-81b30afabd1736e3dec4bb05c377b2d28317c2fe.zip
Save calculator params to database
-rw-r--r--.gitignore1
-rw-r--r--app.coffee32
-rw-r--r--public/css/calculator.less3
-rw-r--r--public/css/common.less2
-rw-r--r--public/img/bitcoin.pngbin0 -> 17755 bytes
-rw-r--r--public/js/calculator.coffee4
-rw-r--r--views/calculator.html5
-rw-r--r--views/index.html9
8 files changed, 44 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index eb5eed7b..941fcea6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-transactions.json
.htpasswd
.rvmrc
db/migrate.rb
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&currency=true'
+ path: '/t/depthcalc.json?symbol=' + symbol + '&type=bid&amount=1000&currency=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,
diff --git a/public/css/calculator.less b/public/css/calculator.less
index 8103ed5e..bdacbd0c 100644
--- a/public/css/calculator.less
+++ b/public/css/calculator.less
@@ -6,5 +6,6 @@ input[type="text"] { height: 1.4em; }
span.btn { font-size: 1.4em; width: 80%; }
small, label { color: #999; font-size: 1.2em; }
strong#total { font-size: 2em; }
-#logo { padding: 10px 0; }
+#title { display: none; }
+#logo { display: none; padding: 10px 0; }
#error { margin-top: 10px; }
diff --git a/public/css/common.less b/public/css/common.less
index fb105aec..05af2492 100644
--- a/public/css/common.less
+++ b/public/css/common.less
@@ -3,7 +3,7 @@
body { text-align: center; }
body { font-size: 100%; line-height: 100%; }
-h1 { width: 100%; text-align: center; }
+h1 { width: 100%; }
div.container-fluid {
width: 600px;
diff --git a/public/img/bitcoin.png b/public/img/bitcoin.png
new file mode 100644
index 00000000..148d0c0b
--- /dev/null
+++ b/public/img/bitcoin.png
Binary files differ
diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee
index ed199920..08757249 100644
--- a/public/js/calculator.coffee
+++ b/public/js/calculator.coffee
@@ -21,7 +21,7 @@ $(->
if client? and client
$.getJSON('client/' + client, (data) ->
user = data[0]
- g.title = user.title
+ g.title = user.name
g.address = user.address
g.commission = user.commission
g.logo = user.logo
@@ -81,7 +81,7 @@ setupPage = ->
if logo
$('#logo').attr('src', logo).show()
else
- $('#title').html(title)
+ $('#title').html(title).show()
$('#address').html(address)
$('#received').hide()
diff --git a/views/calculator.html b/views/calculator.html
index 38d9cdae..792b5b02 100644
--- a/views/calculator.html
+++ b/views/calculator.html
@@ -12,9 +12,8 @@
<div class="container-fluid">
<div id="calculator" style="display: none">
<input id="client" type="hidden" value="{{client}}" />
- <h1 id="title">Bitcoin Payment Calculator</h1>
-
- <img id="logo" src="img/logo.jpg" alt="Logo" style="display: none" />
+ <h1 id="title"></h1>
+ <img id="logo" src="img/logo.jpg" alt="Logo" />
<label for="exchange">Exchange Rate:</label>
<input type="text" id="exchange" value="0" disabled="disabled" />
diff --git a/views/index.html b/views/index.html
index eaf27c69..4080f66c 100644
--- a/views/index.html
+++ b/views/index.html
@@ -9,11 +9,14 @@
</head>
<body>
<div class="container-fluid">
- <form action="calculator">
+ <form action="create" method="post">
<h1>Calculator Setup</h1>
- <label for="title">Name:</label>
- <input type="text" id="title" name="title" />
+ <label for="login">Alias:</label>
+ <input type="text" id="login" name="login" />
+
+ <label for="name">Title:</label>
+ <input type="text" id="name" name="name" />
<label for="address">Bitcoin Address:</label>
<input type="text" id="address" name="address" />