e949/api/user/delete.php

38 lines
982 B
PHP
Raw Normal View History

<?php
require_once("../_auth.php");
require_once("../_utils.php");
require_once("./index.php");
2023-08-30 07:11:13 +05:30
// Delete existing account
function User_Delete ($id) {
global $db;
$s = $db->prepare("delete from users where id = $id");
$s->bind_param("s", $id);
return $s->execute() !== false;
}
2023-08-30 07:11:13 +05:30
if (ThisFileIsRequested(__FILE__)) {
require_once("../_json.php");
2023-08-30 07:11:13 +05:30
if (isset($_REQUEST["id"]) && $LOGGED_IN) {
if (!ctype_digit($_REQUEST["id"]))
ReturnJSONError($Err_RDP_InvalidID, "id must be numeric");
$UserID = intval($_REQUEST["id"]);
2023-08-30 07:11:13 +05:30
} elseif (!isset($_REQUEST["id"]) && $LOGGED_IN) {
$UserID = $_SESSION["userid"];
} else {
2023-08-30 07:11:13 +05:30
ReturnJSONError($Err_RDP_InvalidID, "valid session must be provided");
}
2023-08-30 07:11:13 +05:30
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();
ReturnJSONData(["success" => $result]);
}
?>