From 3fb0ac54a814dcc134f9f6299e37d5d71e452a05 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 30 Mar 2016 15:54:42 +0200 Subject: Improve error messages for login form --- js/codeq/login.js | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'js') diff --git a/js/codeq/login.js b/js/codeq/login.js index bf47917..dff70e5 100644 --- a/js/codeq/login.js +++ b/js/codeq/login.js @@ -25,16 +25,20 @@ along with this program. If not, see . */ jqNavBarRight = $('.nav.navbar-nav.navbar-right'), jqNavigationHomeBtn = $('#navigation-home'), jqAAILoginBtn = $('#aai-login-button'), - jqLoginForm = $('#login-form'), + jqForm = $('#login-form'), jqSignupBtn = $('#signup-button'), jqLangSelect = jqScreen.find('.lang-select'), jqDisabledOverlay = $('#disabled'), - jqLoginFailed = jqLoginForm.find('.error.failed'); + jqMessages = jqForm.find('.error'); //the loginCallbackFunction is used here and in the AAI login as well codeq.loginCallbackFunction = function (data) { - jqDisabledOverlay.css('display', 'none'); - if (data.code !== 0) throw new Error('Login failed, code: ' + data.code + ', message: ' + data.message); + if (data.code === 1) { + throw new Error('Wrong username/password'); + } + else if (data.code !== 0) { + throw new Error('Login failed'); + } //nav signed in... $('#signed-in-title').html(data.name||data.username||data.email||'undefined'); @@ -62,14 +66,27 @@ along with this program. If not, see . */ }; var loginFun = function() { - jqLoginFailed.hide(); + jqMessages.hide(); + jqDisabledOverlay.show(); codeq.comms.connect() .then(function () { return codeq.comms.login($('#username').val(), $('#password').val()); }) .then(codeq.loginCallbackFunction) - .fail(function (reason) { - jqLoginFailed.show(); + .fail(function (error) { + switch (error.message) { + case 'Wrong username/password': + jqForm.find('.error.wrong-user-or-pw').show(); + break; + case 'Connection failed': + jqForm.find('.error.connection-failed').show(); + break; + default: + jqForm.find('.error.login-failed').show(); + } + }) + .finally(function () { + jqDisabledOverlay.hide(); }) .done(); }; @@ -80,14 +97,14 @@ along with this program. If not, see . */ 'enter': function(){ jqNavigationHomeBtn.off('click');//remove the click listener of this element here jqNavBarRight.css('display','none');//hide settings etc. - jqLoginFailed.hide(); + jqMessages.hide(); $('#signed-in-title').html(''); codeq.samlLogin = false;//remove saml login flag $('.saml-login-hide').css('display','');//if we login the normal way we want to show the change password buttons. if we enter the saml login they will be hidden // setup login form - jqLoginForm.on('submit', function (e) { + jqForm.on('submit', function (e) { e.preventDefault(); loginFun(); }); @@ -112,7 +129,7 @@ along with this program. If not, see . */ }, 'exit' : function(){ //remove the listener from the buttons specific to this page - jqLoginForm.off('submit'); + jqForm.off('submit'); jqSignupBtn.off('click'); jqAAILoginBtn.off('click'); jqLangSelect.off('click'); @@ -125,7 +142,7 @@ along with this program. If not, see . */ e.preventDefault(); }); jqNavBarRight.css('display',''); - jqLoginFailed.hide(); + jqMessages.hide(); } }); })(); -- cgit v1.2.1