Наконец-то разобрался с сессиями, +минорные фиксы

This commit is contained in:
2023-08-31 23:26:16 +03:00
parent ae719995ee
commit 983a5d0353
3 changed files with 27 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ require_once("./index.php");
// Delete existing account
function User_Delete ($id) {
global $db;
$s = $db->prepare("delete from users where id = $id");
$s = $db->prepare("delete from users where id = ?");
$s->bind_param("s", $id);
return $s->execute() !== false;
}
@@ -32,11 +32,16 @@ if (ThisFileIsRequested(__FILE__)) {
ReturnJSONError($Err_RDP_InvalidID, "valid session must be provided");
}
// If its attempt to delete other account
if (!User_HasRole($_SESSION["userid"], "admin") && $_SESSION["userid"] !== $UserID)
ReturnJSONError($Err_DP_NotEnoughRole, "you need to be admin to delete other accounts");
$result = User_Delete($UserID);
EndSession();
// If it was self-deletion
if ($UserID === $_SESSION["userid"])
EndSession();
ReturnJSONData(["success" => $result]);
}
?>