remove junk

This commit is contained in:
Tomáš Měšťan 2024-03-21 10:18:39 +01:00
parent fe71309446
commit dfc58eacb4
5 changed files with 11 additions and 26 deletions

@ -399,14 +399,12 @@ async function updateUserProfile() {
const firstName = document.getElementById("updateFirstName").value; const firstName = document.getElementById("updateFirstName").value;
const lastName = document.getElementById("updateLastName").value; const lastName = document.getElementById("updateLastName").value;
const nickname = document.getElementById("updateNickname").value; const nickname = document.getElementById("updateNickname").value;
const minecraftNick = document.getElementById("updateMinecraftNick").value;
const data = { const data = {
action: "update_user_profile", action: "update_user_profile",
first_name: firstName, first_name: firstName,
last_name: lastName, last_name: lastName,
nickname: nickname, nickname: nickname,
minecraft_nick: minecraftNick,
}; };
await doAction('/account', data, "Profile update Successful!", "Profile update failed.", false); await doAction('/account', data, "Profile update Successful!", "Profile update failed.", false);
@ -431,7 +429,6 @@ async function populateUserInfoFields(userData) {
document.getElementById("updateFirstName").value = userData.FirstName || ""; document.getElementById("updateFirstName").value = userData.FirstName || "";
document.getElementById("updateLastName").value = userData.LastName || ""; document.getElementById("updateLastName").value = userData.LastName || "";
document.getElementById("updateNickname").value = userData.Nickname || ""; document.getElementById("updateNickname").value = userData.Nickname || "";
document.getElementById("updateMinecraftNick").value = userData.MinecraftNick || "";
document.getElementById("updateNewEmail").value = userData.Email || ""; document.getElementById("updateNewEmail").value = userData.Email || "";
} }

@ -25,8 +25,7 @@ function endpoint($endpoint_data): array
"update_user_profile" => updateUserProfile( "update_user_profile" => updateUserProfile(
$endpoint_data["first_name"], $endpoint_data["first_name"],
$endpoint_data["last_name"], $endpoint_data["last_name"],
$endpoint_data["nickname"], $endpoint_data["nickname"]
$endpoint_data["minecraft_nick"]
), ),
"update_user_email" => updateUserEmail( "update_user_email" => updateUserEmail(
$endpoint_data["email"] $endpoint_data["email"]

@ -68,7 +68,6 @@ function setDefaultSessionData(): void
$_SESSION["last_name"] = ""; $_SESSION["last_name"] = "";
$_SESSION["nickname"] = ""; $_SESSION["nickname"] = "";
$_SESSION["email"] = ""; $_SESSION["email"] = "";
$_SESSION["minecraft_nickname"] = "";
$_SESSION["privilege_level"] = $routerConfig["permissions"]["logged_out"]; $_SESSION["privilege_level"] = $routerConfig["permissions"]["logged_out"];
} }
@ -89,7 +88,7 @@ function verifyPassword($userID, $password): bool
function UpdateSession(): void function UpdateSession(): void
{ {
global $mysqli; global $mysqli;
$stmt = $mysqli->prepare("SELECT FirstName, LastName, Nickname, Email, MinecraftNick, PrivilegeLevel, LastLoginAt, LoginCount, ClassID, FavoriteColor FROM Users WHERE ID = ? AND isActivated = 1"); $stmt = $mysqli->prepare("SELECT FirstName, LastName, Nickname, Email, PrivilegeLevel, LastLoginAt, LoginCount, FavoriteColor FROM Users WHERE ID = ? AND isActivated = 1");
$stmt->bind_param("i", $_SESSION["ID"]); $stmt->bind_param("i", $_SESSION["ID"]);
$stmt->execute(); $stmt->execute();
@ -97,24 +96,20 @@ function UpdateSession(): void
$last_name = ""; $last_name = "";
$nickname = ""; $nickname = "";
$email = ""; $email = "";
$minecraft_nickname = "";
$privilege_level = 0; $privilege_level = 0;
$class_id = 0;
$favorite_color = 0; $favorite_color = 0;
$lastLoginAt = null; $lastLoginAt = null;
$loginCount = 0; $loginCount = 0;
$stmt->bind_result($first_name, $last_name, $nickname, $email, $minecraft_nickname, $privilege_level, $lastLoginAt, $loginCount, $class_id, $favorite_color); $stmt->bind_result($first_name, $last_name, $nickname, $email, $privilege_level, $lastLoginAt, $loginCount, $favorite_color);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
$_SESSION["first_name"] = $first_name; $_SESSION["first_name"] = $first_name;
$_SESSION["last_name"] = $last_name; $_SESSION["last_name"] = $last_name;
$_SESSION["nickname"] = $nickname; $_SESSION["nickname"] = $nickname;
$_SESSION["email"] = $email; $_SESSION["email"] = $email;
$_SESSION["minecraft_nickname"] = $minecraft_nickname;
$_SESSION["privilege_level"] = $privilege_level; $_SESSION["privilege_level"] = $privilege_level;
$_SESSION["lastLoginAt"] = $lastLoginAt; $_SESSION["lastLoginAt"] = $lastLoginAt;
$_SESSION["loginCount"] = $loginCount; $_SESSION["loginCount"] = $loginCount;
$_SESSION["class_id"] = $class_id;
$_SESSION["favorite_color"] = $favorite_color; $_SESSION["favorite_color"] = $favorite_color;
} }
@ -207,17 +202,17 @@ function changePassword($oldPassword, $newPassword): array
// Function to update user profile // Function to update user profile
function updateUserProfile($firstName, $lastName, $nickname, $minecraft_nickname): array function updateUserProfile($firstName, $lastName, $nickname): array
{ {
global $mysqli; global $mysqli;
$status = ["Status" => "Fail"]; $status = ["Status" => "Fail"];
if (isLoggedIn() && !empty($firstName) && !empty($lastName) && !empty($nickname) && !empty($minecraft_nickname)) { if (isLoggedIn() && !empty($firstName) && !empty($lastName) && !empty($nickname) ) {
$userID = $_SESSION["ID"]; $userID = $_SESSION["ID"];
$stmt = $mysqli->prepare("UPDATE Users SET FirstName = ?, LastName = ?, Nickname = ?, MinecraftNick = ? WHERE ID = ?"); $stmt = $mysqli->prepare("UPDATE Users SET FirstName = ?, LastName = ?, Nickname = ? WHERE ID = ?");
/** @noinspection SpellCheckingInspection */ /** @noinspection SpellCheckingInspection */
$stmt->bind_param("ssssi", $firstName, $lastName, $nickname, $minecraft_nickname, $userID); $stmt->bind_param("ssssi", $firstName, $lastName, $nickname, $userID);
$stmt->execute(); $stmt->execute();
if ($stmt->affected_rows > 0) { if ($stmt->affected_rows > 0) {
@ -281,7 +276,7 @@ function getUserInfo(): array
if(isLoggedIn()) { if(isLoggedIn()) {
global $mysqli; global $mysqli;
$userID = $_SESSION["ID"]; $userID = $_SESSION["ID"];
$stmt = $mysqli->prepare("SELECT FirstName, LastName, Nickname, Email, MinecraftNick FROM Users WHERE ID = ?"); $stmt = $mysqli->prepare("SELECT FirstName, LastName, Nickname, Email FROM Users WHERE ID = ?");
$stmt->bind_param("i", $userID); $stmt->bind_param("i", $userID);
$stmt->execute(); $stmt->execute();
@ -289,9 +284,8 @@ function getUserInfo(): array
$lastName = ""; $lastName = "";
$nickname = ""; $nickname = "";
$email = ""; $email = "";
$minecraft_nickname = "";
$stmt->bind_result($firstName, $lastName, $nickname, $email, $minecraft_nickname); $stmt->bind_result($firstName, $lastName, $nickname, $email);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
UpdateSession(); UpdateSession();
@ -302,8 +296,7 @@ function getUserInfo(): array
"FirstName" => $firstName, "FirstName" => $firstName,
"LastName" => $lastName, "LastName" => $lastName,
"Nickname" => $nickname, "Nickname" => $nickname,
"Email" => $email, "Email" => $email
"MinecraftNick" => $minecraft_nickname
]; ];
} }
@ -350,7 +343,7 @@ function listUsers(): array
if (isUserAdmin()) { if (isUserAdmin()) {
$users = []; $users = [];
$result = $mysqli->query("SELECT ID, FirstName, LastName, Nickname, Email, MinecraftNick, PrivilegeLevel, CreatedAt, RegisteredAt, LastLoginAt, LoginCount, CreatedBy FROM Users WHERE isActivated = 1"); $result = $mysqli->query("SELECT ID, FirstName, LastName, Nickname, Email, PrivilegeLevel, CreatedAt, RegisteredAt, LastLoginAt, LoginCount, CreatedBy FROM Users WHERE isActivated = 1");
// Check if the query executed Successfully // Check if the query executed Successfully
if ($result) { if ($result) {

@ -168,7 +168,6 @@ function getPage($site_name_in = null, $page_name_in = null): string
"UserInfo_LastName" => $_SESSION["last_name"], "UserInfo_LastName" => $_SESSION["last_name"],
"UserInfo_Nickname" => $_SESSION["nickname"], "UserInfo_Nickname" => $_SESSION["nickname"],
"UserInfo_Email" => $_SESSION["email"], "UserInfo_Email" => $_SESSION["email"],
"UserInfo_MinecraftNick" => $_SESSION["minecraft_nickname"],
]; ];
} }
$dynamic_script = generateScriptData($dynamic_script_data); $dynamic_script = generateScriptData($dynamic_script_data);

@ -16,9 +16,6 @@
<label for="updateNickname">Nickname:</label> <label for="updateNickname">Nickname:</label>
<input type="text" id="updateNickname" name="updateNickname" required><br> <input type="text" id="updateNickname" name="updateNickname" required><br>
<label for="updateMinecraftNick">Minecraft Nick:</label>
<input type="text" id="updateMinecraftNick" name="updateMinecraftNick" required><br>
<button type="button" onclick="updateUserProfile()">Update Profile</button> <button type="button" onclick="updateUserProfile()">Update Profile</button>
<br><br> <br><br>