Fix reset password bug

This commit is contained in:
Vortrex
2022-06-12 09:15:54 -05:00
parent 49e773a4ea
commit 5c071aa928
2 changed files with 22 additions and 18 deletions

View File

@@ -20,8 +20,8 @@ let passwordReset = {
// =========================================================================== // ===========================================================================
function initResetPasswordGUI() { function initResetPasswordGUI() {
logToConsole(LOG_DEBUG, `[VRR.GUI] Creating password reset GUI ...`); logToConsole(LOG_DEBUG, `[VRR.GUI] Creating password reset GUI ...`);
passwordReset.window = mexui.window(getScreenWidth()/2-150, getScreenHeight()/2-135, 300, 275, 'RESET PASSWORD', { passwordReset.window = mexui.window(getScreenWidth() / 2 - 150, getScreenHeight() / 2 - 135, 300, 275, 'RESET PASSWORD', {
main: { main: {
backgroundColour: toColour(secondaryColour[0], secondaryColour[1], secondaryColour[2], windowAlpha), backgroundColour: toColour(secondaryColour[0], secondaryColour[1], secondaryColour[2], windowAlpha),
transitionTime: 500, transitionTime: 500,
@@ -38,7 +38,7 @@ function initResetPasswordGUI() {
borderColour: toColour(0, 0, 0, 0), borderColour: toColour(0, 0, 0, 0),
}, },
}); });
passwordReset.window.titleBarIconSize = toVector2(0,0); passwordReset.window.titleBarIconSize = toVector2(0, 0);
passwordReset.window.titleBarHeight = 0; passwordReset.window.titleBarHeight = 0;
passwordReset.window.titleBarShown = false; passwordReset.window.titleBarShown = false;
@@ -82,7 +82,7 @@ function initResetPasswordGUI() {
}); });
passwordReset.emailInput.placeholder = "Email"; passwordReset.emailInput.placeholder = "Email";
passwordReset.resetPasswordButton = passwordReset.window.button(180, 240, 100, 15, 'RESET PASSWORD', { passwordReset.resetPasswordButton = passwordReset.window.button(20, 205, 260, 30, 'RESET PASSWORD', {
main: { main: {
backgroundColour: toColour(primaryColour[0], primaryColour[1], primaryColour[2], buttonAlpha), backgroundColour: toColour(primaryColour[0], primaryColour[1], primaryColour[2], buttonAlpha),
textColour: toColour(primaryTextColour[0], primaryTextColour[1], primaryTextColour[2], 255), textColour: toColour(primaryTextColour[0], primaryTextColour[1], primaryTextColour[2], 255),
@@ -134,14 +134,14 @@ function showResetPasswordGUI() {
mexui.focusedControl = passwordReset.emailInput; mexui.focusedControl = passwordReset.emailInput;
guiSubmitKey = checkResetPassword; guiSubmitKey = checkResetPassword;
showLocaleChooserGUI(new Vec2(getScreenWidth()/2-(localeChooser.window.size.x/2), passwordReset.window.position.y+passwordReset.window.size.y+20)); showLocaleChooserGUI(new Vec2(getScreenWidth() / 2 - (localeChooser.window.size.x / 2), passwordReset.window.position.y + passwordReset.window.size.y + 20));
//showSmallGameMessage(`If you don't have a mouse cursor, press ${toUpperCase(getKeyNameFromId(disableGUIKey))} to disable GUI`, COLOUR_WHITE, 7500); //showSmallGameMessage(`If you don't have a mouse cursor, press ${toUpperCase(getKeyNameFromId(disableGUIKey))} to disable GUI`, COLOUR_WHITE, 7500);
} }
// =========================================================================== // ===========================================================================
function checkResetPassword() { function checkResetPassword() {
logToConsole(LOG_DEBUG, `[VRR.GUI] Checking password reset with server ...`); logToConsole(LOG_DEBUG, `[VRR.GUI] Checking password reset with server (${passwordReset.emailInput.lines[0]}) ...`);
sendNetworkEventToServer("vrr.checkResetPassword", passwordReset.emailInput.lines[0]); sendNetworkEventToServer("vrr.checkResetPassword", passwordReset.emailInput.lines[0]);
} }
@@ -157,12 +157,12 @@ function resetPasswordFailed(errorMessage) {
// =========================================================================== // ===========================================================================
function resetPasswordCodeInputGUI() { function resetPasswordCodeInputGUI() {
logToConsole(LOG_DEBUG|LOG_WARN, `[VRR.GUI] Server reports password reset email confirmation was successful. Asking for code ...`); logToConsole(LOG_DEBUG | LOG_WARN, `[VRR.GUI] Server reports password reset email confirmation was successful. Asking for code ...`);
closeAllWindows(); closeAllWindows();
passwordReset.messageLabel.text = getLocaleString("GUIResetPasswordCodeInputLabel"); passwordReset.messageLabel.text = getLocaleString("GUIResetPasswordCodeInputLabel");
//passwordReset.messageLabel.styles.main.textColour = toColour(180, 32, 32, 255); //passwordReset.messageLabel.styles.main.textColour = toColour(180, 32, 32, 255);
passwordReset.emailInput.text = ""; passwordReset.emailInput.lines[0] = "";
passwordReset.emailInput.placeholder = getLocaleString("GUIResetPasswordCodePlaceholder"); passwordReset.emailInput.placeholder = getLocaleString("GUIResetPasswordCodePlaceholder");
guiSubmitKey = checkResetPassword; guiSubmitKey = checkResetPassword;
@@ -172,7 +172,7 @@ function resetPasswordCodeInputGUI() {
// =========================================================================== // ===========================================================================
function resetPasswordEmailInputGUI() { function resetPasswordEmailInputGUI() {
logToConsole(LOG_DEBUG|LOG_WARN, `[VRR.GUI] Server reports password reset request was approved. Asking for email ...`); logToConsole(LOG_DEBUG | LOG_WARN, `[VRR.GUI] Server reports password reset request was approved. Asking for email ...`);
closeAllWindows(); closeAllWindows();
passwordReset.messageLabel.text = getLocaleString("GUIResetPasswordConfirmEmailLabel"); passwordReset.messageLabel.text = getLocaleString("GUIResetPasswordConfirmEmailLabel");
@@ -188,8 +188,8 @@ function resetPasswordEmailInputGUI() {
function switchToLoginGUI() { function switchToLoginGUI() {
guiSubmitKey = false; guiSubmitKey = false;
closeAllWindows(); closeAllWindows();
showLoginGUI(); showLoginGUI();
} }
// =========================================================================== // ===========================================================================

View File

@@ -801,9 +801,10 @@ function createAccount(name, password, email = "") {
// =========================================================================== // ===========================================================================
function checkLogin(client, password) { async function checkLogin(client, password) {
getPlayerData(client).loginAttemptsRemaining = getPlayerData(client).loginAttemptsRemaining - 1; getPlayerData(client).loginAttemptsRemaining = getPlayerData(client).loginAttemptsRemaining - 1;
if (getPlayerData(client).loginAttemptsRemaining <= 0) { if (getPlayerData(client).loginAttemptsRemaining <= 0) {
getPlayerData(client).customDisconnectReason = "Kicked - Failed to login";
disconnectPlayer(client); disconnectPlayer(client);
} }
@@ -842,7 +843,7 @@ function checkLogin(client, password) {
// Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it. // Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it.
//if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { //if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) {
// sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); // await sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame());
//} //}
return false; return false;
} }
@@ -859,7 +860,7 @@ function checkLogin(client, password) {
// Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it. // Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it.
//if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { //if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) {
// sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); // await sendAccountLoginFailedNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame());
//} //}
return false; return false;
} }
@@ -879,7 +880,7 @@ function checkLogin(client, password) {
// Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it. // Disabling email login alerts for now. It hangs the server for a couple seconds. Need a way to thread it.
//if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) { //if (isAccountEmailVerified(getPlayerData(client).accountData) && !isAccountSettingFlagEnabled(getPlayerData(client).accountData, getAccountSettingsFlagValue("AuthAttemptAlert"))) {
// sendAccountLoginSuccessNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame()); // await sendAccountLoginSuccessNotification(getPlayerData(client).accountData.emailAddress, getPlayerName(client), getPlayerIP(client), getGame());
//} //}
} }
@@ -987,6 +988,7 @@ function checkRegistration(client, password, confirmPassword = "", emailAddress
if (doesServerHaveTesterOnlyEnabled() && !isPlayerATester(client)) { if (doesServerHaveTesterOnlyEnabled() && !isPlayerATester(client)) {
setTimeout(function () { setTimeout(function () {
getPlayerData(client).customDisconnectReason = "Kicked - Not a tester";
disconnectPlayer(client); disconnectPlayer(client);
}, 5000); }, 5000);
@@ -1032,22 +1034,23 @@ function checkAccountResetPasswordRequest(client, inputText) {
getPlayerData(client).passwordResetCode = passwordResetCode; getPlayerData(client).passwordResetCode = passwordResetCode;
showPlayerResetPasswordCodeInputGUI(client); showPlayerResetPasswordCodeInputGUI(client);
sendPasswordResetEmail(client, passwordResetCode); sendPasswordResetEmail(client, passwordResetCode);
logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} submitted successful email for password reset. Sending email and awaiting verification code input ...`); logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} submitted successful email for password reset. Sending email and awaiting verification code input (${passwordResetCode}) ...`);
break; break;
} }
case VRR_RESETPASS_STATE_CODEINPUT: { case VRR_RESETPASS_STATE_CODEINPUT: {
logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} submitted code for password reset (${inputText}) ...`);
if (inputText != "") { if (inputText != "") {
if (getPlayerData(client).passwordResetCode == toUpperCase(inputText)) { if (getPlayerData(client).passwordResetCode == toUpperCase(inputText)) {
getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_SETPASS; getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_SETPASS;
showPlayerChangePasswordGUI(client, getLocaleString(client)); showPlayerChangePasswordGUI(client);
logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} entered the correct reset password verification code. Awaiting new password input ...`); logToConsole(LOG_INFO, `${getPlayerDisplayForConsole(client)} entered the correct reset password verification code. Awaiting new password input ...`);
} else { } else {
getPlayerData(client).passwordResetState = VRR_RESETPASS_STATE_NONE;
getPlayerData(client).passwordResetAttemptsRemaining = getPlayerData(client).passwordResetAttemptsRemaining - 1; getPlayerData(client).passwordResetAttemptsRemaining = getPlayerData(client).passwordResetAttemptsRemaining - 1;
logToConsole(LOG_INFO | LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct, ${getPlayerData(client).passwordResetAttemptsRemaining} attempts remaining)`); logToConsole(LOG_INFO | LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct, ${getPlayerData(client).passwordResetAttemptsRemaining} attempts remaining)`);
if (getPlayerData(client).passwordResetAttemptsRemaining <= 0) { if (getPlayerData(client).passwordResetAttemptsRemaining <= 0) {
logToConsole(LOG_INFO | LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct, no more attempts remaining, kicking ...)`); logToConsole(LOG_INFO | LOG_WARN, `${getPlayerDisplayForConsole(client)} failed to reset their password (verification code not correct, no more attempts remaining, kicking ...)`);
getPlayerData(client).customDisconnectReason = "Kicked - Failed to login";
disconnectPlayer(client); disconnectPlayer(client);
return false; return false;
} }
@@ -1570,6 +1573,7 @@ function checkPlayerTwoFactorAuthentication(client, authCode) {
} }
} }
getPlayerData(client).customDisconnectReason = "Kicked - Failed to login";
disconnectPlayer(client); disconnectPlayer(client);
return false; return false;
} }