First post request

This commit is contained in:
Pierre
2017-12-24 17:45:05 +01:00
parent bdf47b9c26
commit 85bf596e54
4 changed files with 135 additions and 6 deletions

View File

@ -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;
}