Edit APIs
This commit is contained in:
parent
8b7e465796
commit
1e037cd6a2
@ -289,11 +289,11 @@ function addActivationCodes($count): array
|
|||||||
$output = ["Status" => "Fail"]; // Default Status is "Fail"
|
$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("INSERT INTO Users VALUES ActivationToken = ?, CreatedAt = NOW(), CreatedBy = ?");
|
||||||
|
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$activationCode = generateActivationToken();
|
$activationCode = generateActivationToken();
|
||||||
$stmt->bind_param("sii", $activationCode, $_SESSION["ID"], $_SESSION["ID"]);
|
$stmt->bind_param("si", $activationCode, $_SESSION["ID"]);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
if ($stmt->affected_rows > 0) {
|
if ($stmt->affected_rows > 0) {
|
||||||
@ -342,20 +342,44 @@ function listActivationCodes(): array
|
|||||||
|
|
||||||
if (isUserAdmin()) {
|
if (isUserAdmin()) {
|
||||||
$activationCodes = [];
|
$activationCodes = [];
|
||||||
$result = $mysqli->query("SELECT ActivationToken, CreatedAt, CreatedBy FROM Users");
|
|
||||||
|
|
||||||
// Check if the query executed Successfully
|
// Use placeholders in the query
|
||||||
if ($result) {
|
$query = "SELECT ActivationToken, CreatedAt, CreatedBy FROM Users WHERE isActivated = 0";
|
||||||
while ($row = $result->fetch_assoc()) {
|
$stmt = $mysqli->prepare($query);
|
||||||
$activationCodes[] = $row;
|
|
||||||
|
if ($stmt) {
|
||||||
|
// Bind the result variables
|
||||||
|
$activationToken = "";
|
||||||
|
$createdAt = "";
|
||||||
|
$createdBy = "";
|
||||||
|
$stmt->bind_result($activationToken, $createdAt, $createdBy);
|
||||||
|
|
||||||
|
// Execute the prepared statement
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
// Fetch the results into the bound variables
|
||||||
|
while ($stmt->fetch()) {
|
||||||
|
$activationCodes[] = [
|
||||||
|
'ActivationToken' => $activationToken,
|
||||||
|
'CreatedAt' => $createdAt,
|
||||||
|
'CreatedBy' => $createdBy
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$output["Status"] = "Success";
|
|
||||||
$output["ActivationCodes"] = $activationCodes;
|
// Check if any results were fetched
|
||||||
|
if (!empty($activationCodes)) {
|
||||||
|
$output["Status"] = "Success";
|
||||||
|
$output["ActivationCodes"] = $activationCodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the statement
|
||||||
|
$stmt->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function deleteUser($userID): array
|
function deleteUser($userID): array
|
||||||
{
|
{
|
||||||
global $mysqli, $routerConfig;
|
global $mysqli, $routerConfig;
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<script>
|
<script>
|
||||||
function addActivationCodes() {
|
async function addActivationCodes() {
|
||||||
const count = document.getElementById("activationCodeCount").value;
|
const count = document.getElementById("activationCodeCount").value;
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
const data = new URLSearchParams();
|
||||||
data.append("action", "add_activation_codes");
|
data.append("action", "add_activation_codes");
|
||||||
data.append("count", count);
|
data.append("count", count);
|
||||||
|
|
||||||
doAccountAction(data, "Activation codes added Successfully!", "Activation codes addition failed.");
|
const result = await doAccountAction(data, "Activation codes added Successfully!", "Activation codes addition failed.");
|
||||||
|
|
||||||
|
displayUserList(result.ActivationCodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listUsers() {
|
async function listUsers() {
|
||||||
@ -48,11 +50,13 @@
|
|||||||
tableContainer.appendChild(table);
|
tableContainer.appendChild(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
function listActivationCodes() {
|
async function listActivationCodes() {
|
||||||
const data = new URLSearchParams();
|
const data = new URLSearchParams();
|
||||||
data.append("action", "list_activation_codes");
|
data.append("action", "list_activation_codes");
|
||||||
|
|
||||||
doAccountAction(data, "Activation code list retrieved Successfully!", "Activation code list retrieval failed.");
|
const result = await doAccountAction(data, "Activation code list retrieved Successfully!", "Activation code list retrieval failed.");
|
||||||
|
|
||||||
|
displayUserList(result.ActivationCodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteUser() {
|
function deleteUser() {
|
||||||
@ -82,7 +86,7 @@
|
|||||||
<h1>Add Activation Codes</h1>
|
<h1>Add Activation Codes</h1>
|
||||||
<form>
|
<form>
|
||||||
<label for="activationCodeCount">Activation Code Count:</label>
|
<label for="activationCodeCount">Activation Code Count:</label>
|
||||||
<input type="text" id="activationCodeCount" name="activationCodeCount" required>
|
<input type="text" id="activationCodeCount" name="activationCodeCount" required><br>
|
||||||
|
|
||||||
<button type="button" onclick="addActivationCodes()">Add Activation Codes</button>
|
<button type="button" onclick="addActivationCodes()">Add Activation Codes</button>
|
||||||
</form>
|
</form>
|
||||||
@ -106,7 +110,7 @@
|
|||||||
<h1>Delete User</h1>
|
<h1>Delete User</h1>
|
||||||
<form>
|
<form>
|
||||||
<label for="userId">User ID:</label>
|
<label for="userId">User ID:</label>
|
||||||
<input type="text" id="userId" name="userId" required>
|
<input type="text" id="userId" name="userId" required><br>
|
||||||
|
|
||||||
<button type="button" onclick="deleteUser()">Delete User</button>
|
<button type="button" onclick="deleteUser()">Delete User</button>
|
||||||
</form>
|
</form>
|
||||||
@ -116,7 +120,7 @@
|
|||||||
<h1>Delete Activation Code</h1>
|
<h1>Delete Activation Code</h1>
|
||||||
<form>
|
<form>
|
||||||
<label for="activationCode">Activation Code:</label>
|
<label for="activationCode">Activation Code:</label>
|
||||||
<input type="text" id="activationCode" name="activationCode" required>
|
<input type="text" id="activationCode" name="activationCode" required><br>
|
||||||
|
|
||||||
<button type="button" onclick="deleteActivationCode()">Delete Activation Code</button>
|
<button type="button" onclick="deleteActivationCode()">Delete Activation Code</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
function changePassword() {
|
function changePassword() {
|
||||||
const userId = document.getElementById("changeUserId").value;
|
const oldPassword = document.getElementById("changeoldPassword").value;
|
||||||
const newPassword = document.getElementById("changeNewPassword").value;
|
const newPassword = document.getElementById("changeNewPassword").value;
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
const data = new URLSearchParams();
|
||||||
data.append("action", "change_password");
|
data.append("action", "change_password");
|
||||||
data.append("user_id", userId);
|
data.append("old_password", oldPassword);
|
||||||
data.append("new_password", newPassword);
|
data.append("new_password", newPassword);
|
||||||
|
|
||||||
doChangePassword(data, "Password change Successful!", "Password change failed.");
|
doChangePassword(data, "Password change Successful!", "Password change failed.");
|
||||||
@ -87,56 +87,53 @@
|
|||||||
<div class="form-container" id="changePasswordForm">
|
<div class="form-container" id="changePasswordForm">
|
||||||
<h1>Change Password</h1>
|
<h1>Change Password</h1>
|
||||||
<form>
|
<form>
|
||||||
<label for="changeUserId">User ID:</label>
|
|
||||||
<input type="text" id="changeUserId" name="changeUserId" required>
|
|
||||||
|
|
||||||
<label for="changeOldPassword">Old Password:</label>
|
<label for="changeOldPassword">Old Password:</label>
|
||||||
<input type="password" id="changeOldPassword" name="changeOldPassword" required>
|
<input type="password" id="changeOldPassword" name="changeOldPassword" required><br>
|
||||||
|
|
||||||
<label for="changeNewPassword">New Password:</label>
|
<label for="changeNewPassword">New Password:</label>
|
||||||
<input type="password" id="changeNewPassword" name="changeNewPassword" required>
|
<input type="password" id="changeNewPassword" name="changeNewPassword" required><br>
|
||||||
|
|
||||||
<button type="button" onclick="changePassword()">Change Password</button>
|
<button type="button" onclick="changePassword()">Change Password</button>
|
||||||
</form>
|
</form><br>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-container" id="updateUserProfileForm">
|
<div class="form-container" id="updateUserProfileForm">
|
||||||
<h1>Update User Profile</h1>
|
<h1>Update User Profile</h1>
|
||||||
<form>
|
<form>
|
||||||
<label for="updateUserIdProfile">User ID:</label>
|
<label for="updateUserIdProfile">User ID:</label>
|
||||||
<input type="text" id="updateUserIdProfile" name="updateUserIdProfile" required>
|
<input type="text" id="updateUserIdProfile" name="updateUserIdProfile" required><br>
|
||||||
|
|
||||||
<label for="updateFirstName">First Name:</label>
|
<label for="updateFirstName">First Name:</label>
|
||||||
<input type="text" id="updateFirstName" name="updateFirstName" required>
|
<input type="text" id="updateFirstName" name="updateFirstName" required><br>
|
||||||
|
|
||||||
<label for="updateLastName">Last Name:</label>
|
<label for="updateLastName">Last Name:</label>
|
||||||
<input type="text" id="updateLastName" name="updateLastName" required>
|
<input type="text" id="updateLastName" name="updateLastName" required><br>
|
||||||
|
|
||||||
<label for="updateNickname">Nickname:</label>
|
<label for="updateNickname">Nickname:</label>
|
||||||
<input type="text" id="updateNickname" name="updateNickname" required>
|
<input type="text" id="updateNickname" name="updateNickname" required><br>
|
||||||
|
|
||||||
<label for="updateMinecraftNick">Minecraft Nick:</label>
|
<label for="updateMinecraftNick">Minecraft Nick:</label>
|
||||||
<input type="text" id="updateMinecraftNick" name="updateMinecraftNick" required>
|
<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>
|
||||||
</form>
|
</form><br>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-container" id="getUserInfoForm">
|
<div class="form-container" id="getUserInfoForm">
|
||||||
<h1>Get User Info</h1>
|
<h1>Get User Info</h1>
|
||||||
<form>
|
<form>
|
||||||
<button type="button" onclick="getUserInfo()">Get User Info</button>
|
<button type="button" onclick="getUserInfo()">Get User Info</button>
|
||||||
</form>
|
</form><br>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-container" id="updateUserEmailForm">
|
<div class="form-container" id="updateUserEmailForm">
|
||||||
<h1>Update User Email</h1>
|
<h1>Update User Email</h1>
|
||||||
<form>
|
<form>
|
||||||
<label for="updateNewEmail">New Email:</label>
|
<label for="updateNewEmail">New Email:</label>
|
||||||
<input type="email" id="updateNewEmail" name="updateNewEmail" required>
|
<input type="email" id="updateNewEmail" name="updateNewEmail" required><br>
|
||||||
|
|
||||||
<button type="button" onclick="updateEmail()">Update Email</button>
|
<button type="button" onclick="updateEmail()">Update Email</button>
|
||||||
</form>
|
</form><br>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="button" onclick="logout()">Logout</button>
|
<button type="button" onclick="logout()">Logout</button><br>
|
||||||
|
Loading…
Reference in New Issue
Block a user