diff --git a/src/client/scripts/createaccount.js b/src/client/scripts/createaccount.js index 343609646..4d3cfb125 100644 --- a/src/client/scripts/createaccount.js +++ b/src/client/scripts/createaccount.js @@ -64,8 +64,8 @@ element_usernameInput.addEventListener('focusout', (event) => { // Check usernam // Reset variable because it now exists. usernameError = document.getElementById("usernameerror"); - let result_message = result.reason; // translate the message from the server if a translation is available + let result_message = result.reason; if (translations["server-websocket"][result_message]) result_message = translations["server-websocket"][result_message]; usernameError.textContent = result_message; updateSubmitButton(); diff --git a/src/client/scripts/game/websocket.js b/src/client/scripts/game/websocket.js index 4356e87f2..d22a84d13 100644 --- a/src/client/scripts/game/websocket.js +++ b/src/client/scripts/game/websocket.js @@ -203,9 +203,8 @@ const websocket = (function(){ /** @type {WebsocketMessage} */ let message; try { - // Parse the stringified JSON message + // Parse the stringified JSON message and translate the message from the server if a translation is available message = JSON.parse(serverMessage.data); // { sub, action, value, id } - // translate the message from the server if a translation is available if (translations["server-websocket"][message]) message = translations["server-websocket"][message]; } catch (error) { return console.error('Error parsing incoming message as JSON:', error); diff --git a/src/client/scripts/login.js b/src/client/scripts/login.js index 8d183d791..a94f0d55f 100644 --- a/src/client/scripts/login.js +++ b/src/client/scripts/login.js @@ -67,9 +67,17 @@ const sendLogin = (username, password) => { element_forgot.className = 'forgotvisible'; } updateSubmitButton(); - let result_message = result['message']; + // translate the message from the server if a translation is available + let result_message = result['message']; if (translations["server-websocket"][result_message]) result_message = translations["server-websocket"][result_message]; + + // append the login cooldown if it exists + let login_cooldown = ("login_cooldown" in result ? result["login_cooldown"] : undefined); + if (login_cooldown !== undefined){ + const seconds_plurality = login_cooldown == 1 ? translations["server-websocket"]["second"] : translations["server-websocket"]["seconds"]; + result_message += ` ${login_cooldown} ${seconds_plurality}.` + } loginErrorElement.textContent = result_message; element_submitButton.disabled = false; } diff --git a/src/client/views/member.ejs b/src/client/views/member.ejs index 064086254..d0b858e3b 100644 --- a/src/client/views/member.ejs +++ b/src/client/views/member.ejs @@ -5,6 +5,7 @@ const translations = <%-JSON.stringify({ ...t('header.javascript', {returnObjects: true}), ...t('member.javascript', {returnObjects: true}), + ...t('server.javascript', {returnObjects: true}) })%>; diff --git a/src/server/controllers/authController.js b/src/server/controllers/authController.js index b46ed4f2b..4823cefd4 100644 --- a/src/server/controllers/authController.js +++ b/src/server/controllers/authController.js @@ -217,7 +217,10 @@ function rateLimitLogin(res, browserAgent) { // Too many attempts! if (timeSinceLastAttemptsSecs <= loginAttemptData[browserAgent].cooldownTimeSecs) { // Still on cooldown - res.status(401).json({ 'message': "login_failure_retry_soon"}); + res.status(401).json({ + 'message': "login_failure_retry_soon", + 'login_cooldown': Math.floor(loginAttemptData[browserAgent].cooldownTimeSecs - timeSinceLastAttemptsSecs) + }); // res.status(401).json({ 'message': `Failed to login, try again in ${Math.floor(loginAttemptData[browserAgent].cooldownTimeSecs - timeSinceLastAttemptsSecs)} seconds.`}); // Reset the timer to auto-delete them from the login attempt data diff --git a/translation/en-US.toml b/translation/en-US.toml index 96bb379e5..7310d9311 100644 --- a/translation/en-US.toml +++ b/translation/en-US.toml @@ -504,7 +504,9 @@ text_box = "The system for verifying accounts has been updated to be more reliab forbidden_wrong_account = "Forbidden. This is not your account." username_and_password_required = "Username and password are required." username_and_password_string = "Username and password must be a string." -login_failure_retry_soon = "Failed to login, try again soon." +login_failure_retry_soon = "Failed to login, try again in" +seconds = "seconds" +second = "second" username_length = "Username must be between 3-20 characters" username_letters = "Username must only contain letters A-Z and numbers 0-9" username_taken = "That username is taken"