mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-18 16:18:04 +00:00
First post request
This commit is contained in:
@ -133,4 +133,31 @@ function check_user_id(int $userID) : bool {
|
||||
return false; //Invalid
|
||||
|
||||
return true; //Valid
|
||||
}
|
||||
|
||||
/**
|
||||
* Get userID posted in a request and return it if there
|
||||
* isn't any error
|
||||
*
|
||||
* @param string $name Optionnal, the name of the post field
|
||||
* @return int User ID
|
||||
* @throws RestError in case of error
|
||||
*/
|
||||
function getPostUserID(string $name = "userID") : int {
|
||||
|
||||
//Get userID post
|
||||
if(!isset($_POST[$name]))
|
||||
Rest_fatal_error(400, "Please specify a userID in '".$name."' !");
|
||||
|
||||
$userID = toInt($_POST[$name]);
|
||||
|
||||
//Check userID validity
|
||||
if(!check_user_id($userID))
|
||||
Rest_fatal_error(400, "Invalid userID in '".$name."' !");
|
||||
|
||||
//Check if user exits
|
||||
if(!CS::get()->components->user->exists($userID))
|
||||
Rest_fatal_error(404, "Specified user in '".$name."' not found !");
|
||||
|
||||
return $userID;
|
||||
}
|
Reference in New Issue
Block a user