some more stuff

This commit is contained in:
Bruno Rybársky 2024-02-03 17:30:51 +01:00
parent 87c12b0bb4
commit 6f07524342
5 changed files with 40 additions and 12 deletions

@ -28,6 +28,9 @@ function endpoint($endpoint_data): array
$endpoint_data["nickname"], $endpoint_data["nickname"],
$endpoint_data["minecraft_nick"] $endpoint_data["minecraft_nick"]
), ),
"update_user_email" => updateUserEmail(
$endpoint_data["email"]
),
"get_user_info" => getUserInfo(), "get_user_info" => getUserInfo(),
//logged in end //logged in end
//admin start //admin start

@ -265,9 +265,9 @@ function getUserInfo(): array
$stmt->bind_result($firstName, $lastName, $nickname, $email, $minecraft_nickname); $stmt->bind_result($firstName, $lastName, $nickname, $email, $minecraft_nickname);
$stmt->fetch(); $stmt->fetch();
$stmt->close(); $stmt->close();
$output = ["Status" => "Success"]; $output["Status"] = "Success";
$output += [ $output["UserInfo"] = [
"ID" => $userID, "ID" => $userID,
"FirstName" => $firstName, "FirstName" => $firstName,
"LastName" => $lastName, "LastName" => $lastName,
@ -286,6 +286,8 @@ function addActivationCodes($count): array
global $mysqli, $routerConfig; global $mysqli, $routerConfig;
$activationCodes = []; $activationCodes = [];
$output = ["Status" => "Fail"]; // Default Status is "Fail"
if (is_numeric($count) && $count > 0 && $_SESSION["privilege_level"] >= $routerConfig["user_admin_permission_level"] && isLoggedIn()) { 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 = ?"); $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"), "CreatedAt" => date("Y-m-d H:i:s"),
"CreatedBy" => $_SESSION["ID"] "CreatedBy" => $_SESSION["ID"]
]; ];
$output["Status"] = "Success";
$output["ActivationCodes"] = $activationCodes;
} }
} }
$stmt->close(); $stmt->close();
} }
return $activationCodes; return $output;
} }
function listUsers(): array function listUsers(): array
{ {
global $mysqli, $routerConfig; global $mysqli, $routerConfig;
$users = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
if (isUserAdmin()) { if (isUserAdmin()) {
$users = []; $users = [];
@ -323,16 +327,18 @@ function listUsers(): array
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$users[] = $row; $users[] = $row;
} }
$output["Status"] = "Success";
$output["Users"] = $users;
} }
} }
return $users; return $output;
} }
function listActivationCodes(): array function listActivationCodes(): array
{ {
global $mysqli, $routerConfig; global $mysqli, $routerConfig;
$activationCodes = ["Status" => "Fail"]; // Default Status is "Fail" $output = ["Status" => "Fail"]; // Default Status is "Fail"
if (isUserAdmin()) { if (isUserAdmin()) {
$activationCodes = []; $activationCodes = [];
@ -343,10 +349,11 @@ function listActivationCodes(): array
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$activationCodes[] = $row; $activationCodes[] = $row;
} }
$output["Status"] = "Success";
$output["ActivationCodes"] = $activationCodes;
} }
} }
return $output;
return $activationCodes;
} }
function deleteUser($userID): array function deleteUser($userID): array

@ -5,10 +5,9 @@ require_once "lib/account.php";
global $routerConfig; global $routerConfig;
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"] . "userActions.html");
if (isUserAdmin()) {
$output .= file_get_contents($routerConfig["template_dir"] . "adminActions.html");
} }
return [ return [

@ -2,6 +2,5 @@
<h2>Niekto to pobabral</h2> <h2>Niekto to pobabral</h2>
<h1 class="error-code">500</h1> <h1 class="error-code">500</h1>
<h3><i class="ri-error-warning-line"></i> Nejaký neschopný vývojár nevedel robiť túto stránku. <i class="ri-error-warning-line"></i></h3> <h3><i class="ri-error-warning-line"></i> Nejaký neschopný vývojár nevedel robiť túto stránku. <i class="ri-error-warning-line"></i></h3>
<h4>__TEMPLATE_ERROR__</h4>
<a href="/index" class="back"><i class="ri-arrow-left-line"></i> SPÄŤ DOMOV</a> <a href="/index" class="back"><i class="ri-arrow-left-line"></i> SPÄŤ DOMOV</a>
</div> </div>

@ -33,6 +33,16 @@
doAccountAction(data, "Profile update Successful!", "Profile update failed."); 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() { async function getUserInfo() {
const userId = document.getElementById("getUserInfoId").value; const userId = document.getElementById("getUserInfoId").value;
@ -120,6 +130,16 @@
</form> </form>
</div> </div>
<div class="form-container" id="updateUserEmailForm">
<h1>Update User Email</h1>
<form>
<label for="updateNewEmail">New Email:</label>
<input type="email" id="updateNewEmail" name="updateNewEmail" required>
<button type="button" onclick="updateEmail()">Update Email</button>
</form>
</div>
<button type="button" onclick="logout()">Logout</button> <button type="button" onclick="logout()">Logout</button>
<!-- Include other user action forms similarly --> <!-- Include other user action forms similarly -->