From 3b565f4f4dcea55779e00493e7cf507cf8392010 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 13 Jul 2014 23:50:47 -0700 Subject: Confirm password --- public/css/calculator.less | 8 +++----- public/js/setup.coffee | 18 ++++++++++++++++-- routes/users.coffee | 9 +++++++++ views/calculator/setup.html | 9 +++++++-- views/users/new.html | 10 +++++++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/public/css/calculator.less b/public/css/calculator.less index be8a7e7d..2b7ffc92 100644 --- a/public/css/calculator.less +++ b/public/css/calculator.less @@ -17,15 +17,14 @@ div.container-fluid { .form-group { .form-control { height: 40px; padding: 3px; } - label { font-weight: normal; display: block; } - p, span, input[type="text"], select, label { font-size: 20px; } + label { font-weight: normal; font-size: 14px; display: block; } + p, span, input[type="text"], select { font-size: 18px; } span, label { color: #999; } .form-control { display: inline-block; } } form#setup, form#register { - .form-control { width: 300px; } - #address { font-size: 12px; } + .form-control { width: 400px; } } @@ -39,7 +38,6 @@ div#calculator { } td#total { font-weight: bold; text-align: right; } -small { color: #999; } div#calculator p#address { font-size: 1em; margin-top: 20px; } diff --git a/public/js/setup.coffee b/public/js/setup.coffee index dcb58bcb..e8b4e09b 100644 --- a/public/js/setup.coffee +++ b/public/js/setup.coffee @@ -4,19 +4,20 @@ #= require jsbn2.js #= require check_address.js +g = exports ? this +g.proceed = false + $(-> $.getJSON("/js/rates.json", (data) -> currencies = Object.keys(data) currencies = currencies.sort() currencies.pop() - $.each(currencies, (i, v) -> $('#currency').append("") ) $("#currency option[value='CAD']").attr('selected', 'selected') - user = $('#username').val() $('#currency').change(-> @@ -41,6 +42,19 @@ $(-> $(this).css('color', 'red') ) + $('#confirm').blur(-> + $('#confirm_error').remove() + if $('#password').val() != $('#confirm').val() + $('#password, #confirm').parent().addClass('has-error') + $('#confirm').parent().after('
Passwords don\'t match
') + else + $('#password, #confirm').parent().removeClass('has-error') + ) + + $('#setup').submit(-> + return false if $('.has-error').length() + ) + if user $('#setup').attr('action', "/#{user}/update").attr('method', 'post') $.getJSON("/#{user}.json", (data) -> diff --git a/routes/users.coffee b/routes/users.coffee index 04284d5a..beae3eb0 100644 --- a/routes/users.coffee +++ b/routes/users.coffee @@ -53,11 +53,20 @@ module.exports = (sessions) -> ) create: (req, res) -> + errormsg = "" userkey = "user:"+req.body.username db.hgetall(userkey, (err, obj) -> if obj res.redirect(req.body.username) else + if req.body.confirm != req.body.password + errormsg += "Passwords must match" + return res.render('users/new', + js: (-> global.js), + css: (-> global.css), + error: errormsg + ) + bcrypt.hash(req.body.password, 12, (err, hash) -> db.sadd("users",userkey) db.hmset(userkey, diff --git a/views/calculator/setup.html b/views/calculator/setup.html index e125eea9..26977c7a 100644 --- a/views/calculator/setup.html +++ b/views/calculator/setup.html @@ -48,8 +48,13 @@
- - + + +
+ +
+ +

diff --git a/views/users/new.html b/views/users/new.html index 258e8119..e9874217 100644 --- a/views/users/new.html +++ b/views/users/new.html @@ -6,12 +6,15 @@ Bitcoin Payment Calculator {{#css}}calculator{{/css}} - {{#js}}setup{{/js}} + {{#js}}register{{/js}}

Register

+ {{#error}} +
{{error}}
+ {{/error}}
@@ -21,6 +24,11 @@
+ +
+ + +
-- cgit v1.2.3