diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/codeq/change_password.js | 17 | ||||
-rw-r--r-- | js/codeq/login.js | 2 | ||||
-rw-r--r-- | js/codeq/signup.js | 46 |
3 files changed, 43 insertions, 22 deletions
diff --git a/js/codeq/change_password.js b/js/codeq/change_password.js index 562f4b2..6311764 100644 --- a/js/codeq/change_password.js +++ b/js/codeq/change_password.js @@ -22,24 +22,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ */ (function(){ "use strict"; - var jqScreen = $('#screen-change-pass'), + var jqScreen = $('#screen-change-password'), + jqChangePassForm = $('#change-password-form'), jqNew = $('#change-password-new'), jqVerify = $('#change-password-verify'), jqCancelBtn = $('#change-password-cancel'), - jqChangePassForm = $('#change-password-form'); + jqErrorMismatch = jqChangePassForm.find('.error.mismatch'); codeq.globalStateMachine.register('changePassword',{ 'jqScreen': jqScreen, 'isModal': true, - 'enter': function(){ + 'enter': function() { + jqErrorMismatch.hide(); jqCancelBtn.on('click',function(){ history.back();//forces a transition to the previous state }); - jqChangePassForm.on('submit',function(event) { - + jqChangePassForm.on('submit', function (e) { + jqErrorMismatch.hide(); if (jqNew.val() != jqVerify.val()) { - alert('Passwords do not match.'); + jqErrorMismatch.show(); } else { codeq.comms.changePassword(jqNew.val()) @@ -54,7 +56,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ }) .done(); } - event.preventDefault(); // Prevent the form from submitting via the browser. + e.preventDefault(); // Prevent the form from submitting via the browser. }); @@ -62,6 +64,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ $('#disabled').css('display', 'none'); }, 'exit' : function(){ + jqErrorMismatch.hide(); jqChangePassForm.off('submit'); jqCancelBtn.off('click'); jqScreen.css('display', 'none'); diff --git a/js/codeq/login.js b/js/codeq/login.js index 9b87762..bf47917 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -29,7 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ jqSignupBtn = $('#signup-button'), jqLangSelect = jqScreen.find('.lang-select'), jqDisabledOverlay = $('#disabled'), - jqLoginFailed = jqScreen.find('.login-failed'); + jqLoginFailed = jqLoginForm.find('.error.failed'); //the loginCallbackFunction is used here and in the AAI login as well codeq.loginCallbackFunction = function (data) { diff --git a/js/codeq/signup.js b/js/codeq/signup.js index d41f1d5..7f28e9f 100644 --- a/js/codeq/signup.js +++ b/js/codeq/signup.js @@ -31,12 +31,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ jqExitSignUpBtn = $('#signup-cancel'), jqLangSelect = jqScreen.find('.lang-select'), jqNavBarRight = $('.nav.navbar-nav.navbar-right'), - jqNavigationHomeBtn = $('#navigation-home'); + jqNavigationHomeBtn = $('#navigation-home'), + jqMessages = jqFormSignUp.find('.error,.success'), + redirectTimeout = null; codeq.globalStateMachine.register('signup',{ 'jqScreen': jqScreen, - 'enter': function(){ + 'enter': function() { + jqMessages.hide(); jqNavigationHomeBtn.off('click');//remove the click listener of this element here jqNavBarRight.css('display','none');//hide settings etc. $('#signed-in-title').html(''); @@ -47,22 +50,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ }); //prepare listener for successfull signup - jqFormSignUp.on('submit',function(event) { + jqFormSignUp.on('submit', function(e) { + jqMessages.hide(); if (jqPassword.val() != jqVerify.val()) { - alert('Passwords do not match.'); + jqFormSignUp.find('.error.mismatch').show(); } 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); - - var newUsername = jqUsername.val();//saving before transition (which will reset the value of the field) - //back to login - codeq.globalStateMachine.transition('login'); - alert('Welcome '+ newUsername +'. Thanks for signing up.'); - //assume user wants to sign-in with signed username - $("#username").val(newUsername); - + var jqSuccess = jqFormSignUp.find('.success'), + username = jqUsername.val(); + switch (data.code) { + case 0: // everything OK + $("#username").val(username); + jqSuccess.find('.username').text(username); + jqSuccess.show(); + // back to login after short pause + redirectTimeout = setTimeout(function() { + codeq.globalStateMachine.transition('login'); + }, 2000); + break; + case 10: // username exists + jqFormSignUp.find('.error.username-exists').show(); + break; + default: + throw new Error(data.message); + } }) .fail(function (reason) { codeq.log.error('Signup failed: ' + reason, reason); @@ -70,7 +83,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ }) .done(); } - event.preventDefault(); // Prevent the form from submitting via the browser. + e.preventDefault(); // Prevent the form from submitting via the browser. }); // setup language selection links @@ -80,6 +93,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ }); }, 'exit' : function(){ + if (redirectTimeout !== null) { + clearTimeout(redirectTimeout); + redirectTimeout = null; + } + jqMessages.hide(); jqScreen.css('display', 'none'); //re-enable the click listener jqNavigationHomeBtn.on('click', function(e){ |