From d93c44493e2ebd17b6d0c1524e3342c059fc36c7 Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Sun, 22 May 2022 13:30:46 -0500 Subject: [PATCH] Fix password reset stuff (got reverted somehow) --- scripts/server/account.js | 52 +++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/scripts/server/account.js b/scripts/server/account.js index 513097d6..a431bc5f 100644 --- a/scripts/server/account.js +++ b/scripts/server/account.js @@ -1016,27 +1016,41 @@ function checkAccountResetPasswordRequest(client, inputText) { return false; } - if(getPlayerData(client).passwordResetState == VRR_RESETPASS_STATE_NONE) { - if(toLowerCase(getPlayerData(client).accountData.emailAddress) != toLowerCase(inputText)) { - logToConsole(LOG_DEBUG|LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (email not correct)`); - return false; + switch(getPlayerData(client).passwordResetState) { + case VRR_RESETPASS_STATE_EMAILCONFIRM: { + if(toLowerCase(getPlayerData(client).accountData.emailAddress) != toLowerCase(inputText)) { + logToConsole(LOG_INFO|LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (email not correct)`); + showPlayerErrorGUI(client, getLocaleString(client, "GUIErrorResetPasswordFailedInvalidEmail"), getLocaleString(client, "GUIErrorTitle"), getLocaleString(client, "GUIOkButton")); + return false; + } + + let passwordResetCode = toUpperCase(generateEmailVerificationCode()); + getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_CODEINPUT; + getPlayerData(client).passwordResetCode = passwordResetCode; + showPlayerResetPasswordCodeInputGUI(client); + sendPasswordResetEmail(client, passwordResetCode); + logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} submitted successful email for password reset. Sending email and awaiting verification code input ...`); + break; } - let passwordResetCode = toUpperCase(generateEmailVerificationCode()); - getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_CODEINPUT; - getPlayerData(client).passwordResetCode = passwordResetCode; - sendPasswordResetEmail(client, passwordResetCode); - showPlayerResetPasswordCodeInputGUI(client); - logToConsole(LOG_DEBUG|LOG_WARN, `${getPlayerDisplayForConsole(client)} reset their password. Awaiting verification code input ...`); - } else if(getPlayerData(client).passwordResetState == VRR_RESETPASS_STATE_CODEINPUT) { - if(getPlayerData(client).passwordResetCode == toUpperCase(inputText)) { - getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_SETPASS; - showPlayerChangePasswordGUI(client); - logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)} entered the correct reset password verification code. Awaiting new password input ...`); - } else { - getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_NONE; - disconnectPlayer(client); - logToConsole(LOG_DEBUG|LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct)`); + case VRR_RESETPASS_STATE_CODEINPUT: { + if(getPlayerData(client).passwordResetCode == toUpperCase(inputText)) { + getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_SETPASS; + showPlayerChangePasswordGUI(client, getLocaleString(client)); + logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} entered the correct reset password verification code. Awaiting new password input ...`); + } else { + getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_NONE; + disconnectPlayer(client); + logToConsole(LOG_INFO|LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct)`); + } + break; + } + + case VRR_RESETPASS_STATE_NONE: { + logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} requested a password reset. Awaiting email input ...`); + showPlayerResetPasswordEmailInputGUI(client); + getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_EMAILCONFIRM; + break; } }