From 60f21d2927b5173ecbd9cccc8bbe91018029c471 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 16 Jan 2013 00:05:18 -0800 Subject: Test for username existence --- app.coffee | 1 + public/js/index.coffee | 21 +++++++++++++++++++++ routes/users.coffee | 6 ++++++ views/main/about.html | 6 ++---- views/main/index.html | 2 +- 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 @@

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.

- 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 software to participate is free and open source so anyone can run it on their computer to earn bitcoins.

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 @@
-
+

Sign Up

-- cgit v1.2.3