From 5a4918db39a3e31e214ee2bc88f1123381503b50 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 6 Jan 2018 18:26:02 +0100 Subject: [PATCH] Created User->canCreatePosts method --- RestControllers/userController.php | 2 +- classes/components/user.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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