From 894df8afb3c70f2b17437d10d43a7b62402f59c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Pu=C5=A1nik?= Date: Mon, 12 Oct 2015 11:52:00 +0200 Subject: ResetPassword: form validation --- index.html | 10 +++++----- js/codeq/profile.js | 50 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/index.html b/index.html index 15148ba..9dd8a7c 100644 --- a/index.html +++ b/index.html @@ -351,7 +351,7 @@

Sign up

diff --git a/js/codeq/profile.js b/js/codeq/profile.js index 687a3c7..2759be3 100644 --- a/js/codeq/profile.js +++ b/js/codeq/profile.js @@ -18,6 +18,8 @@ else { codeq.comms.signup(jqUsername.val(), jqName.val(), jqEmail.val(), jqPassword.val()) .then(function (data) { + if (data.code !== 0) throw new Error('Signup failed, code: ' + data.code + ', message: ' + data.message); + //back to login $('#modalSignUp').modal('hide'); alert('Welcome '+ jqUsername.val() +'. Thanks for signing up.'); @@ -31,34 +33,42 @@ jqPassword.val(''); jqVerify.val(''); }) + .fail(function (reason) { + codeq.log.error('Signup failed: ' + reason, reason); + alert('Signup failed: ' + reason); + }) .done(); } event.preventDefault(); // Prevent the form from submitting via the browser. }); - codeq.profile = { + $('#formChangePassword').submit(function(event) { + var jqNew = $("#modalChangePasswordNew"), + jqVerify = $("#modalChangePasswordVerify"); - 'changePassword': function () { - var jqNew = $("#modalChangePasswordNew"), - jqVerify = $("#modalChangePasswordVerify"); + if (jqNew.val() != jqVerify.val()) { + alert('Passwords do not match.'); + } + else { + codeq.comms.changePassword(jqNew.val()) + .then(function (data) { + if (data.code !== 0) throw new Error('Password change failed, code: ' + data.code + ', message: ' + data.message); - if (jqNew.val() == "" || jqVerify.val() == "") { - alert('Some fields are empty.'); - } - else if (jqNew.val() != jqVerify.val()) { - alert('Passwords do not match.'); - } - else { - codeq.comms.changePassword(jqNew.val()) - .then(function (data) { - $('#modalChangePassword').modal('hide'); - jqNew.val(''); - jqVerify.val(''); - alert('Password changed.'); - }) - .done(); - } + $('#modalChangePassword').modal('hide'); + jqNew.val(''); + jqVerify.val(''); + alert('Password changed.'); + }) + .fail(function (reason) { + codeq.log.error('Password change failed: ' + reason, reason); + alert('Password change failed: ' + reason); + }) + .done(); } + event.preventDefault(); // Prevent the form from submitting via the browser. + }); + + codeq.profile = { }; codeq.globalStateMachine.register('profile',{ -- cgit v1.2.1