2023-08-19 23:45:47 +05:30
|
|
|
<?php // Viewing account data
|
2023-08-12 04:09:17 +05:30
|
|
|
|
|
|
|
require_once("../_auth.php");
|
2023-08-19 23:45:47 +05:30
|
|
|
require_once("../_utils.php");
|
2023-08-12 04:09:17 +05:30
|
|
|
|
|
|
|
|
2023-08-16 09:04:01 +05:30
|
|
|
|
2023-08-19 23:45:47 +05:30
|
|
|
// Check if user with supplied login exists
|
|
|
|
function User_LoginExist ($login): bool {
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$s = $db->prepare("SELECT * FROM users WHERE login = ?");
|
|
|
|
$s->bind_param("s", $login);
|
|
|
|
$s->execute();
|
|
|
|
|
|
|
|
return (bool)$s->get_result()->fetch_assoc();
|
|
|
|
}
|
|
|
|
|
2023-08-16 09:04:01 +05:30
|
|
|
// Check if user has specified role
|
2023-08-19 23:45:47 +05:30
|
|
|
function User_HasRole ($id, $role): bool {
|
2023-08-16 09:04:01 +05:30
|
|
|
global $db;
|
|
|
|
|
|
|
|
$s = $db->prepare("SELECT * FROM users WHERE id = ?");
|
|
|
|
$s->bind_param("s", $id);
|
|
|
|
$s->execute();
|
|
|
|
$d = $s->get_result()->fetch_assoc();
|
|
|
|
|
|
|
|
if (!(bool)$d) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($d["role"] == $role) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user is moderator
|
|
|
|
function User_IsMod ($id) {
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$s = $db->prepare("SELECT * FROM users WHERE id = ?");
|
|
|
|
$s->bind_param("s", $id);
|
|
|
|
$s->execute();
|
|
|
|
$d = $s->get_result()->fetch_assoc();
|
|
|
|
|
|
|
|
if (!(bool)$d) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in_array($d["role"], array("mod", "admin"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get user information from DB
|
|
|
|
function User_GetInfoByID ($id) {
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
$s = $db->prepare("SELECT * FROM users WHERE id = ?");
|
|
|
|
$s->bind_param("s", $id);
|
|
|
|
$s->execute();
|
|
|
|
$d = $s->get_result()->fetch_assoc();
|
|
|
|
|
|
|
|
if (!(bool)$d) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result["id"] = $d["id"];
|
|
|
|
$result["created_at"] = $d["created_at"];
|
|
|
|
$result["login"] = $d["login"];
|
|
|
|
$result["avatar_path"] = $d["avatar_path"];
|
|
|
|
$result["role"] = $d["role"];
|
|
|
|
$result["banned"] = $d["banned"];
|
|
|
|
if ($id === $_SESSION["userid"] || User_IsMod($_SESSION["userid"])) { // User himself and mods can see additional info
|
|
|
|
$result["email"] = $d["email"];
|
|
|
|
$result["invite_id"] = $d["invite_id"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ThisFileIsRequested(__FILE__)) {
|
2023-08-19 23:45:47 +05:30
|
|
|
require_once("../_json.php");
|
|
|
|
|
2023-08-16 09:04:01 +05:30
|
|
|
$UserID = null;
|
|
|
|
|
|
|
|
if (isset($_REQUEST["id"])) {
|
|
|
|
if (!ctype_digit($_REQUEST["id"]))
|
|
|
|
ReturnJSONError($Err_RDP_InvalidID, "id must be numeric");
|
|
|
|
$UserID = intval($_REQUEST["id"]);
|
|
|
|
} else {
|
|
|
|
if ($LOGGED_IN)
|
|
|
|
$UserID = $_SESSION["userid"];
|
|
|
|
else
|
|
|
|
ReturnJSONError($Err_RDP_InvalidID, "id must be specified or valid session must be provided");
|
|
|
|
}
|
|
|
|
|
|
|
|
$ResponseData = User_GetInfoByID($UserID);
|
|
|
|
if ($ResponseData)
|
|
|
|
ReturnJSONData($ResponseData);
|
|
|
|
else
|
|
|
|
ReturnJSONError($Err_DP_IDNotFound, "wrong id");
|
2023-08-12 04:09:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
?>
|