From 6f075243425a0390c5642111543e30b4eed1e610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Sat, 3 Feb 2024 17:30:51 +0100 Subject: [PATCH] some more stuff --- endpoints/global/account.php | 3 +++ lib/account.php | 23 +++++++++++++++-------- pages/home/settings.php | 5 ++--- templates/500.html | 1 - templates/userActions.html | 20 ++++++++++++++++++++ 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/endpoints/global/account.php b/endpoints/global/account.php index 51da7f4..ad4075a 100644 --- a/endpoints/global/account.php +++ b/endpoints/global/account.php @@ -28,6 +28,9 @@ function endpoint($endpoint_data): array $endpoint_data["nickname"], $endpoint_data["minecraft_nick"] ), + "update_user_email" => updateUserEmail( + $endpoint_data["email"] + ), "get_user_info" => getUserInfo(), //logged in end //admin start diff --git a/lib/account.php b/lib/account.php index bebe651..0aff641 100644 --- a/lib/account.php +++ b/lib/account.php @@ -265,9 +265,9 @@ function getUserInfo(): array $stmt->bind_result($firstName, $lastName, $nickname, $email, $minecraft_nickname); $stmt->fetch(); $stmt->close(); - $output = ["Status" => "Success"]; + $output["Status"] = "Success"; - $output += [ + $output["UserInfo"] = [ "ID" => $userID, "FirstName" => $firstName, "LastName" => $lastName, @@ -286,6 +286,8 @@ function addActivationCodes($count): array global $mysqli, $routerConfig; $activationCodes = []; + $output = ["Status" => "Fail"]; // Default Status is "Fail" + if (is_numeric($count) && $count > 0 && $_SESSION["privilege_level"] >= $routerConfig["user_admin_permission_level"] && isLoggedIn()) { $stmt = $mysqli->prepare("UPDATE Users SET ActivationToken = ?, CreatedAt = NOW(), CreatedBy = ? WHERE ID = ?"); @@ -300,19 +302,21 @@ function addActivationCodes($count): array "CreatedAt" => date("Y-m-d H:i:s"), "CreatedBy" => $_SESSION["ID"] ]; + $output["Status"] = "Success"; + $output["ActivationCodes"] = $activationCodes; } } $stmt->close(); } - return $activationCodes; + return $output; } function listUsers(): array { global $mysqli, $routerConfig; - $users = ["Status" => "Fail"]; // Default Status is "Fail" + $output = ["Status" => "Fail"]; // Default Status is "Fail" if (isUserAdmin()) { $users = []; @@ -323,16 +327,18 @@ function listUsers(): array while ($row = $result->fetch_assoc()) { $users[] = $row; } + $output["Status"] = "Success"; + $output["Users"] = $users; } } - return $users; + return $output; } function listActivationCodes(): array { global $mysqli, $routerConfig; - $activationCodes = ["Status" => "Fail"]; // Default Status is "Fail" + $output = ["Status" => "Fail"]; // Default Status is "Fail" if (isUserAdmin()) { $activationCodes = []; @@ -343,10 +349,11 @@ function listActivationCodes(): array while ($row = $result->fetch_assoc()) { $activationCodes[] = $row; } + $output["Status"] = "Success"; + $output["ActivationCodes"] = $activationCodes; } } - - return $activationCodes; + return $output; } function deleteUser($userID): array diff --git a/pages/home/settings.php b/pages/home/settings.php index 4138bd9..6bb7583 100644 --- a/pages/home/settings.php +++ b/pages/home/settings.php @@ -5,10 +5,9 @@ require_once "lib/account.php"; global $routerConfig; +$output = file_get_contents($routerConfig["template_dir"] . "userActions.html"); if (isUserAdmin()) { - $output = file_get_contents($routerConfig["template_dir"] . "adminActions.html"); -} else { - $output = file_get_contents($routerConfig["template_dir"] . "userActions.html"); + $output .= file_get_contents($routerConfig["template_dir"] . "adminActions.html"); } return [ diff --git a/templates/500.html b/templates/500.html index fff8006..065835a 100644 --- a/templates/500.html +++ b/templates/500.html @@ -2,6 +2,5 @@

Niekto to pobabral

500

Nejaký neschopný vývojár nevedel robiť túto stránku.

-

__TEMPLATE_ERROR__

SPÄŤ DOMOV \ No newline at end of file diff --git a/templates/userActions.html b/templates/userActions.html index a630463..dae8ff2 100644 --- a/templates/userActions.html +++ b/templates/userActions.html @@ -33,6 +33,16 @@ doAccountAction(data, "Profile update Successful!", "Profile update failed."); } + function updateEmail() { + const newEmail = document.getElementById("updateNewEmail").value; + + const data = new URLSearchParams(); + data.append("action", "update_user_email"); + data.append("email", newEmail); + + doAccountAction(data, "Email update Successful!", "Email update failed."); + } + async function getUserInfo() { const userId = document.getElementById("getUserInfoId").value; @@ -120,6 +130,16 @@ +
+

Update User Email

+
+ + + + +
+
+