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 lastName = document.getElementById("updateLastName").value;
const nickname = document.getElementById("updateNickname").value;
const minecraftNick = document.getElementById("updateMinecraftNick").value;
const data = {
action: "update_user_profile",
first_name: firstName,
last_name: lastName,
nickname: nickname,
minecraft_nick: minecraftNick,
};
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("updateLastName").value = userData.LastName || "";
document.getElementById("updateNickname").value = userData.Nickname || "";
document.getElementById("updateMinecraftNick").value = userData.MinecraftNick || "";
document.getElementById("updateNewEmail").value = userData.Email || "";
}

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

@ -68,7 +68,6 @@ function setDefaultSessionData(): void
$_SESSION["last_name"] = "";
$_SESSION["nickname"] = "";
$_SESSION["email"] = "";
$_SESSION["minecraft_nickname"] = "";
$_SESSION["privilege_level"] = $routerConfig["permissions"]["logged_out"];
}
@ -89,7 +88,7 @@ function verifyPassword($userID, $password): bool
function UpdateSession(): void
{
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->execute();
@ -97,24 +96,20 @@ function UpdateSession(): void
$last_name = "";
$nickname = "";
$email = "";
$minecraft_nickname = "";
$privilege_level = 0;
$class_id = 0;
$favorite_color = 0;
$lastLoginAt = null;
$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->close();
$_SESSION["first_name"] = $first_name;
$_SESSION["last_name"] = $last_name;
$_SESSION["nickname"] = $nickname;
$_SESSION["email"] = $email;
$_SESSION["minecraft_nickname"] = $minecraft_nickname;
$_SESSION["privilege_level"] = $privilege_level;
$_SESSION["lastLoginAt"] = $lastLoginAt;
$_SESSION["loginCount"] = $loginCount;
$_SESSION["class_id"] = $class_id;
$_SESSION["favorite_color"] = $favorite_color;
}
@ -207,17 +202,17 @@ function changePassword($oldPassword, $newPassword): array
// Function to update user profile
function updateUserProfile($firstName, $lastName, $nickname, $minecraft_nickname): array
function updateUserProfile($firstName, $lastName, $nickname): array
{
global $mysqli;
$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"];
$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 */
$stmt->bind_param("ssssi", $firstName, $lastName, $nickname, $minecraft_nickname, $userID);
$stmt->bind_param("ssssi", $firstName, $lastName, $nickname, $userID);
$stmt->execute();
if ($stmt->affected_rows > 0) {
@ -281,7 +276,7 @@ function getUserInfo(): array
if(isLoggedIn()) {
global $mysqli;
$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->execute();
@ -289,9 +284,8 @@ function getUserInfo(): array
$lastName = "";
$nickname = "";
$email = "";
$minecraft_nickname = "";
$stmt->bind_result($firstName, $lastName, $nickname, $email, $minecraft_nickname);
$stmt->bind_result($firstName, $lastName, $nickname, $email);
$stmt->fetch();
$stmt->close();
UpdateSession();
@ -302,8 +296,7 @@ function getUserInfo(): array
"FirstName" => $firstName,
"LastName" => $lastName,
"Nickname" => $nickname,
"Email" => $email,
"MinecraftNick" => $minecraft_nickname
"Email" => $email
];
}
@ -350,7 +343,7 @@ function listUsers(): array
if (isUserAdmin()) {
$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
if ($result) {

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

@ -16,9 +16,6 @@
<label for="updateNickname">Nickname:</label>
<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>
<br><br>