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["minecraft_nick"]
),
"update_user_email" => updateUserEmail(
$endpoint_data["email"]
),
"get_user_info" => getUserInfo(),
//logged in end
//admin start

@ -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

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

@ -2,6 +2,5 @@
<h2>Niekto to pobabral</h2>
<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>
<h4>__TEMPLATE_ERROR__</h4>
<a href="/index" class="back"><i class="ri-arrow-left-line"></i> SPÄŤ DOMOV</a>
</div>

@ -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 @@
</form>
</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>
<!-- Include other user action forms similarly -->