From 06b43732a96f955ea9245c80ad686e540d46d8b2 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 20 Aug 2018 13:55:05 +0200 Subject: [PATCH] Handle "too many request" login errors. --- assets/js/common/functionsSchema.js | 2 ++ assets/js/langs/en.inc.js | 1 + assets/js/langs/fr.inc.js | 1 + assets/js/pages/login.js | 10 +++++++++- assets/js/user/userLogin.js | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 551a8c9a..75c3a418 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -397,6 +397,8 @@ var ComunicWeb = { * Logout user */ logoutUser: function(afterLogout){}, + + //TODO : implement }, /** diff --git a/assets/js/langs/en.inc.js b/assets/js/langs/en.inc.js index 31afc8ae..e987b3f6 100644 --- a/assets/js/langs/en.inc.js +++ b/assets/js/langs/en.inc.js @@ -181,6 +181,7 @@ ComunicWeb.common.langs.en = { _login_page_password_placeholder: "Password", _login_page_submit: "Sign In", _login_page_error_head: "Login failed", + too_many_login_request_try_again_later: "Too many unsuccessfull login attempts. Please try again later...", _login_page_error_message: "Please check your usermail and password !", _login_page_bad_input: "Please check what you've typed !", _login_page_create_account_lnk: "Create an account", diff --git a/assets/js/langs/fr.inc.js b/assets/js/langs/fr.inc.js index e438b7a0..6e54e3fd 100644 --- a/assets/js/langs/fr.inc.js +++ b/assets/js/langs/fr.inc.js @@ -180,6 +180,7 @@ ComunicWeb.common.langs.fr = { _login_page_password_placeholder: "Mot de passe", _login_page_submit: "Connexion", _login_page_error_head: "La connexion a échouée", + too_many_login_request_try_again_later: "Trop de tentatives de connexion infructueuses. Veuillez réessayer ultérieurement...", _login_page_error_message: "Veuillez vérifier votre identifiant et votre mot de passe !", _login_page_bad_input: "Veuillez vérifier votre saisie...", _login_page_create_account_lnk: "Créer un compte", diff --git a/assets/js/pages/login.js b/assets/js/pages/login.js index 0ef05d0f..509afa28 100644 --- a/assets/js/pages/login.js +++ b/assets/js/pages/login.js @@ -146,8 +146,16 @@ ComunicWeb.pages.login = { * @return {Boolean} True for a success */ displayLoginError: function(){ + + //Find the right error message + if(ComunicWeb.user.userLogin.get_last_attempt_response_code() == 429) + var code = "too_many_login_request_try_again_later"; + //Default error messsage + else + var code = "_login_page_error_message"; + //Create error modal - errorMessageElem = ComunicWeb.common.messages.createCalloutElem(lang("_login_page_error_head"), lang("_login_page_error_message"), "danger"); + errorMessageElem = ComunicWeb.common.messages.createCalloutElem(lang("_login_page_error_head"), lang(code), "danger"); //Apply error modal document.getElementById('loginMessagesTarget').innerHTML = ""; diff --git a/assets/js/user/userLogin.js b/assets/js/user/userLogin.js index 81d076fd..6c922295 100644 --- a/assets/js/user/userLogin.js +++ b/assets/js/user/userLogin.js @@ -16,6 +16,12 @@ ComunicWeb.user.userLogin = { */ __userID: 0, + /** + * @var {number} lastAttemptResponseCode Last login attempt response code + */ + _last_attempt_response_code: 0, + + /** * Tell if user is logged in or not @@ -168,6 +174,7 @@ ComunicWeb.user.userLogin = { //Perform next action if login failed if(!loginstate) { + ComunicWeb.user.userLogin._last_attempt_response_code = result.error.code; afterLogin(loginstate); return false; } @@ -231,4 +238,11 @@ ComunicWeb.user.userLogin = { //Done ! return 0; }, + + /** + * Get last login attempt response code + */ + get_last_attempt_response_code: function(){ + return this._last_attempt_response_code; + } } \ No newline at end of file