diff --git a/RestControllers/userController.php b/RestControllers/userController.php index e58687b..b38743c 100644 --- a/RestControllers/userController.php +++ b/RestControllers/userController.php @@ -151,7 +151,7 @@ class userController //If it is his page, yes by default userID == $userID ? TRUE : //Else check friendship status - CS::get()->components->friends->can_post_text(userID, $userID); + CS::get()->components->user->canCreatePosts(userID, $userID); } //Return user informations diff --git a/classes/components/user.php b/classes/components/user.php index 2aeb618..1372904 100644 --- a/classes/components/user.php +++ b/classes/components/user.php @@ -436,6 +436,36 @@ class User{ return false; } + + /** + * Check if a user can create a post on another user page + * + * @param int $userID The ID of the user who could create post + * @param int $targetID The ID of the user who could receive new posts + * @return bool True if the user is allowed to create post / false else + */ + public function canCreatePosts(int $userID, int $targetID){ + + //If the user is signed out, the response is NO by default + if($userID == 0) + return FALSE; + + //If the two user are friends, the response is yes by default + if($userID === $targetID) + return TRUE; + + //Check if the user is allowed to access user page + if(!$this->userAllowed($userID, $targetID)) + return FALSE; + + //Check if the friendship of the users allow them to create posts + if(!CS::get()->components->friends->can_post_text($userID, $targetID)) + return FALSE; + + //Else the user is allowed + return TRUE; + + } /** * Check whether a user allow comments on his page or not