feat: Add user edit modal and user management pages
- Implemented user edit modal in user_edit.html for editing user details. - Updated sidebar.html to correctly reflect active states for Users and Settings. - Created table-07.html for displaying user data in a structured format. - Added settings.html for managing email content and configurations. - Developed users.html for listing all users with functionality to add and edit users.
This commit is contained in:
48
api/users/delete.php
Normal file
48
api/users/delete.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
require "../api.php";
|
||||
|
||||
$api = new spamhasiApi();
|
||||
$conf = $api->getConf();
|
||||
|
||||
if (!$api->checkAuth()) {
|
||||
die('{"status":500, "error":"Unauthorized"}');
|
||||
}
|
||||
|
||||
if (!isset($_POST["id"])) {
|
||||
die('{"status":500, "error":"Missing fields"}');
|
||||
}
|
||||
|
||||
$id = intval($_POST["id"]);
|
||||
|
||||
$db = $api->getDB();
|
||||
|
||||
$sql = "SELECT COUNT(*) FROM users";
|
||||
$stmt = $db->query($sql);
|
||||
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
if ($count == 1) {
|
||||
die('{"status":500, "error":"Der einzige Benutzer darf NICHT GELÖSCHT WERDEN!"}');
|
||||
}
|
||||
|
||||
$sql = "SELECT username FROM users WHERE id = :id";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->execute([':id' => $id]);
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$name = $result["username"];
|
||||
|
||||
$sql = "DELETE FROM users WHERE id = :id";
|
||||
$stmt = $db->prepare($sql);
|
||||
|
||||
$sql_exec = $stmt->execute([':id' => $id]);
|
||||
|
||||
if (!$sql_exec) {
|
||||
die('{"status":500, "error":"SQL Error"}');
|
||||
}
|
||||
|
||||
if (!unlink($conf["PATH"] . "/tmp/user_sessions/" . $name . ".json")) {
|
||||
die('{"status":500, "error":"Error to remove session file."}');
|
||||
}
|
||||
|
||||
die('{"status":200}');
|
||||
?>
|
||||
Reference in New Issue
Block a user