diff --git a/RestControllers/friendsController.php b/RestControllers/friendsController.php index 2664a3f..a4c1b9f 100644 --- a/RestControllers/friendsController.php +++ b/RestControllers/friendsController.php @@ -51,6 +51,28 @@ class friendsController{ */ public function get_user_list(){ + //Get the ID of the target user + $userID = getPostUserID("userID"); + + //Check whether the friends list of the user is public or not + if(!components()->user->userAllowed(userID, $userID)) + Rest_fatal_error(401, "You are not allowed to access these informations !"); + + //Check if the friendlist of the user is public or not + if(!components()->user->isFriendsListPublic($userID)) + Rest_fatal_error(401, "The friends list of the user is not public !"); + + //Get the list of friend of the user + $friends = CS::get()->components->friends->getList($userID); + + //Process and return it + $IDs = array(); + + foreach($friends as $friend){ + $IDs[] = $friend->getFriendID(); + } + + return $IDs; } /** diff --git a/classes/components/user.php b/classes/components/user.php index 1372904..3ed8719 100644 --- a/classes/components/user.php +++ b/classes/components/user.php @@ -2,7 +2,7 @@ /** * Main user class * - * @author Pierre HUBER + * @author Pierre HUBERT */ class User{ @@ -496,6 +496,35 @@ class User{ return $result[0]["bloquecommentaire"] == 0; } + /** + * Check whether a user allow a public access over its friends list or not + * + * @param int $userID The ID of the user + * @return bool True if the friends list of the user is public / FALSE else + */ + public function isFriendsListPublic(int $userID) : bool { + + //Fetch the information in the database + $conditions = "WHERE ID = ?"; + $condValues = array($userID); + $fields = array("liste_amis_publique"); + + //Perform the request + $result = CS::get()->db->select( + $this->userTable, + $conditions, + $condValues, + $fields + ); + + //Check for errors + if(count($result) == 0) + return FAlSE; + + //Return result + return $result[0]["liste_amis_publique"] == 1; + } + /** * Crypt user password *