Skip to content

Commit

Permalink
Merge pull request #14 from tsevasa/jerm-tmp3
Browse files Browse the repository at this point in the history
fixed login cooldown getting properly displayed
  • Loading branch information
jermOSS authored Jul 19, 2024
2 parents eb3344e + ca21436 commit 53c3170
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/client/scripts/createaccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/client/scripts/game/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion src/client/scripts/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/client/views/member.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const translations = <%-JSON.stringify({
...t('header.javascript', {returnObjects: true}),
...t('member.javascript', {returnObjects: true}),
...t('server.javascript', {returnObjects: true})
})%>;
</script>
<meta charset="utf-8" />
Expand Down
5 changes: 4 additions & 1 deletion src/server/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion translation/en-US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 53c3170

Please sign in to comment.