summaryrefslogtreecommitdiff
path: root/js/codeq
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-30 15:54:42 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-03-30 16:59:23 +0200
commit3fb0ac54a814dcc134f9f6299e37d5d71e452a05 (patch)
treef920bc5aa5845cd22ad1ede9c3f9bc012a5d39c4 /js/codeq
parent07a6662be9f1a59bfe3ae42baa6589d74568c9ce (diff)
Improve error messages for login form
Diffstat (limited to 'js/codeq')
-rw-r--r--js/codeq/login.js39
1 files changed, 28 insertions, 11 deletions
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 <http://www.gnu.org/licenses/>. */
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 <http://www.gnu.org/licenses/>. */
};
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 <http://www.gnu.org/licenses/>. */
'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 <http://www.gnu.org/licenses/>. */
},
'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 <http://www.gnu.org/licenses/>. */
e.preventDefault();
});
jqNavBarRight.css('display','');
- jqLoginFailed.hide();
+ jqMessages.hide();
}
});
})();