Продолжение разработки 23.10.31
Добавлен .gitignore, скрыты несколько нинужных файлов, в целом продолжен запил основных частей функционала, начат микрорефакторинг (теперь концентрация индусского кода будет чуть меньше).
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
<?php // Viewing account data
|
||||
|
||||
// Includes
|
||||
require_once("../_auth.php");
|
||||
require_once("../_utils.php");
|
||||
require_once("../_errorslist.php");
|
||||
require_once("../_types.php");
|
||||
|
||||
|
||||
|
||||
// Check if user with supplied login exists
|
||||
// Functions
|
||||
|
||||
/*
|
||||
* FUNCTION
|
||||
* Check if user with supplied login exists
|
||||
*/
|
||||
function User_LoginExist ($login): bool {
|
||||
global $db;
|
||||
|
||||
@@ -16,7 +24,24 @@ function User_LoginExist ($login): bool {
|
||||
return (bool)$s->get_result()->fetch_assoc();
|
||||
}
|
||||
|
||||
// Check if user has specified role
|
||||
/*
|
||||
* FUNCTION
|
||||
* Check if user with supplied ID exists
|
||||
*/
|
||||
function User_IDExist ($id): bool {
|
||||
global $db;
|
||||
|
||||
$s = $db->prepare("SELECT * FROM users WHERE id = ?");
|
||||
$s->bind_param("s", $id);
|
||||
$s->execute();
|
||||
|
||||
return (bool)$s->get_result()->fetch_assoc();
|
||||
}
|
||||
|
||||
/*
|
||||
* FUNCTION
|
||||
* Check if user has specified role
|
||||
*/
|
||||
function User_HasRole ($id, $role) {
|
||||
global $db;
|
||||
|
||||
@@ -25,18 +50,19 @@ function User_HasRole ($id, $role) {
|
||||
$s->execute();
|
||||
$d = $s->get_result()->fetch_assoc();
|
||||
|
||||
if (!(bool)$d) {
|
||||
if (!(bool)$d)
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($d["role"] == $role) {
|
||||
if ($d["role"] == $role)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if user is moderator
|
||||
/*
|
||||
* FUNCTION
|
||||
* Check if user is moderator (or higher)
|
||||
*/
|
||||
function User_IsMod ($id) {
|
||||
global $db;
|
||||
|
||||
@@ -52,9 +78,32 @@ function User_IsMod ($id) {
|
||||
return in_array($d["role"], array("mod", "admin"));
|
||||
}
|
||||
|
||||
// Get user information from DB
|
||||
function User_GetInfoByID ($id) {
|
||||
global $db, $THIS_USER;
|
||||
|
||||
|
||||
// Methods
|
||||
|
||||
/*
|
||||
* METHOD
|
||||
* Get user information from DB
|
||||
*/
|
||||
function User_GetInfoByID_Method (array $req): ReturnT {
|
||||
global $db, $THIS_USER, $LOGGED_IN;
|
||||
|
||||
// Input sanity checks
|
||||
|
||||
$id = null;
|
||||
if (isset($req["id"])) {
|
||||
if (!ctype_digit($req["id"]))
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "id must be numeric");
|
||||
$id = intval($req["id"]);
|
||||
} else {
|
||||
if ($LOGGED_IN)
|
||||
$id = $THIS_USER;
|
||||
else
|
||||
return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "id must be specified or valid session must be provided");
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
$result = array();
|
||||
|
||||
@@ -63,9 +112,9 @@ function User_GetInfoByID ($id) {
|
||||
$s->execute();
|
||||
$d = $s->get_result()->fetch_assoc();
|
||||
|
||||
if (!(bool)$d) {
|
||||
return null;
|
||||
}
|
||||
if (!(bool)$d)
|
||||
return new ReturnT(err_code: E_UIN_WRONGID, err_desc: "user not found in database");
|
||||
//return new ReturnT(err_code: E_DBE_SELECTFAIL, err_desc: "failed to get user record");
|
||||
|
||||
$result["id"] = $d["id"];
|
||||
$result["created_at"] = $d["created_at"];
|
||||
@@ -78,32 +127,22 @@ function User_GetInfoByID ($id) {
|
||||
$result["invite_id"] = $d["invite_id"];
|
||||
}
|
||||
|
||||
return $result;
|
||||
return new ReturnT(data: $result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ThisFileIsRequested(__FILE__)) {
|
||||
if (Utils_ThisFileIsRequested(__FILE__)) {
|
||||
require_once("../_json.php");
|
||||
|
||||
$UserID = null;
|
||||
$result = User_GetInfoByID_Method($_REQUEST);
|
||||
|
||||
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 = $THIS_USER;
|
||||
else
|
||||
ReturnJSONError($Err_RDP_InvalidID, "id must be specified or valid session must be provided");
|
||||
}
|
||||
|
||||
$ResponseData = User_GetInfoByID($UserID);
|
||||
if ($ResponseData)
|
||||
ReturnJSONData($ResponseData);
|
||||
if ($result->IsError())
|
||||
$result->ThrowJSONError();
|
||||
else
|
||||
ReturnJSONError($Err_DP_IDNotFound, "wrong id");
|
||||
JSON_ReturnData($result->GetData());
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user