aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2013-01-16 00:05:18 -0800
committerAdam Soltys <[email protected]>2013-01-16 00:05:18 -0800
commit60f21d2927b5173ecbd9cccc8bbe91018029c471 (patch)
tree7bd1c9e898ec7d526870d36d8c12d95cc2ddd3fa
parentd78a7c4913184ad00e52839c86dc5d8b54900adf (diff)
downloadcoinos-server-60f21d2927b5173ecbd9cccc8bbe91018029c471.tar.gz
coinos-server-60f21d2927b5173ecbd9cccc8bbe91018029c471.zip
Test for username existence
-rw-r--r--app.coffee1
-rw-r--r--public/js/index.coffee21
-rw-r--r--routes/users.coffee6
-rw-r--r--views/main/about.html6
-rw-r--r--views/main/index.html2
5 files changed, 31 insertions, 5 deletions
diff --git a/app.coffee b/app.coffee
index 5a7a6ce0..9bcd8169 100644
--- a/app.coffee
+++ b/app.coffee
@@ -59,6 +59,7 @@ app.get('/login', sessions.new)
app.post('/login', sessions.create)
app.get('/logout', sessions.destroy)
+app.get('/:user/exists', users.exists)
app.get('/:user.json', authorize, users.json)
app.get('/:user', authorize, users.show)
diff --git a/public/js/index.coffee b/public/js/index.coffee
index ea4f9ac3..940a5e2a 100644
--- a/public/js/index.coffee
+++ b/public/js/index.coffee
@@ -1,8 +1,29 @@
#= require jquery-1.8.2.min.js
+g = exports ? this
+
$(->
fetchExchangeRate('ask')
fetchExchangeRate('bid')
+
+ $('#username').blur(->
+ $.get(
+ "/#{$(this).val()}/exists",
+ username: $(this).val(),
+ (data) ->
+ if data is "true"
+ $('#username').prev().css('color', 'red').html('Username (taken)')
+ g.preventSubmit = true
+ else
+ $('#username').prev().css('color', 'black').html('Username')
+ g.preventSubmit = false
+ )
+ )
+
+ $('#signup').submit(->
+ return false if g.preventSubmit
+ return true
+ )
)
fetchExchangeRate = (type) ->
diff --git a/routes/users.coffee b/routes/users.coffee
index d312dcf5..b39fc8e9 100644
--- a/routes/users.coffee
+++ b/routes/users.coffee
@@ -2,6 +2,12 @@ db = require("redis").createClient()
bcrypt = require('bcrypt')
module.exports = (sessions) ->
+ exists: (req, res) ->
+ db.hgetall(req.params.user, (err, obj) ->
+ if obj? then res.write('true') else res.write('false')
+ res.end()
+ )
+
json: (req, res) ->
db.hgetall(req.params.user, (err, obj) ->
delete obj['password']
diff --git a/views/main/about.html b/views/main/about.html
index 966c90e2..aa1c653e 100644
--- a/views/main/about.html
+++ b/views/main/about.html
@@ -13,13 +13,11 @@
<p>
New bitcoin addresses start with a zero balance. Transactions between addresses are
recorded in a file that gets published on
- the Internet. The file keeps track of every transaction that's ever taken place on the bitcoin network and is used to determine the current balance of every address.
+ the Internet. The file keeps track of every transaction that's ever taken place and therefore knows the balance of every address.
</p>
<p>
- Roughly 150 new bitcoins are
- generated every hour and distributed proportionally to the addresses of people that
- contribute computing power to the network. The
+ New bitcoins are generated every 10 minutes and distributed to people who volunteer computing power to run the bitcoin network. The
<a href="http://bitcoin.org">software to participate</a> is free and open source so anyone can run it on their computer to earn bitcoins.
</p>
diff --git a/views/main/index.html b/views/main/index.html
index ab40422e..3920c568 100644
--- a/views/main/index.html
+++ b/views/main/index.html
@@ -31,7 +31,7 @@
<div class="row-fluid">
<div class="span12 well">
- <form action="/users" method="post" style="float: right; padding-left: 15px;">
+ <form id="signup" action="/users" method="post" style="float: right; padding-left: 15px;">
<h2>Sign Up</h2>
<label for="username">Username:</label>