diff --git a/RestControllers/userController.php b/RestControllers/userController.php index 4c89044..510a4b6 100644 --- a/RestControllers/userController.php +++ b/RestControllers/userController.php @@ -127,7 +127,15 @@ class userController if(!CS::get()->components->user->userAllowed(userID, $userID)) Rest_fatal_error(401, "You are not allowed to access these information !"); - echo "ok"; + //Get user informations + $userInfos = CS::get()->components->user->getUserInfos($userID, true); + + //Check if we got a response + if(count($userInfos) == 0) + Rest_fatal_error(500, "Couldn't get informations about the user !"); + + //Return user informations + return $userInfos; } diff --git a/classes/components/backgroundImage.php b/classes/components/backgroundImage.php new file mode 100644 index 0000000..4c79626 --- /dev/null +++ b/classes/components/backgroundImage.php @@ -0,0 +1,57 @@ +files_path = path_user_data(CS::get()->config->get("backgroundImagePath"), true); + $this->files_url = path_user_data(CS::get()->config->get("backgroundImagePath"), false); + } + + /** + * Returns the path of a background image + * + * @param Integer $userID The ID of the user on which we perform research + * @return String The URL pointing on the background image + */ + public function getPath(int $userID) : string { + //First, check if the background image exists + $backgroundImageRefFile = $this->files_path."adresse_imgfond/".$userID.".txt"; + if(file_exists($backgroundImageRefFile)){ + + //Get background image path and return it + return $this->files_url.file_get_contents($backgroundImageRefFile); + + } + else { + //Return default background image + return $this->files_url.$this->defaultFile; + } + } + +} + +//Register class +Components::register("backgroundImage", new BackgroundImage()); \ No newline at end of file diff --git a/classes/components/user.php b/classes/components/user.php index dd89a22..b720abb 100644 --- a/classes/components/user.php +++ b/classes/components/user.php @@ -162,9 +162,10 @@ class User{ * Get Single User Infos * * @param Integer $userID The user ID + * @param $advanced Get advanced informations about user, for its page for example * @return Array The result of the function (user informations) (empty one if it fails) */ - public function getUserInfos($userID) : array { + public function getUserInfos($userID, bool $advanced = false) : array { //Prepare database request $tablesName = $this->userTable; $conditions = "WHERE utilisateurs.ID = ?"; @@ -180,7 +181,7 @@ class User{ return array(); //No result //Return result - return $this->generateUserInfosArray($userInfos[0]); + return $this->generateUserInfosArray($userInfos[0], $advanced); } /** @@ -222,9 +223,10 @@ class User{ * given the database entry * * @param Array $userInfos The user entry in the database + * @param $advanced Get advanced informations about user or not (to display its profile for example) * @return Array The informations ready to be returned */ - private function generateUserInfosArray(array $userInfos) : array{ + private function generateUserInfosArray(array $userInfos, bool $advanced) : array{ //Prepare return $return = array(); $return['userID'] = $userInfos['ID']; @@ -242,9 +244,13 @@ class User{ //Add account image url $return['accountImage'] = CS::get()->components->accountImage->getPath($return['userID']); - //Only the user may get its mail address - if(userID === $return['userID']) - $return['mailAdress'] = $userInfos['mail']; + //Check if we have to fetch advanced informations + if($advanced){ + + //Add background image url + $return['backgroundImage'] = CS::get()->components->backgroundImage->getPath($return['userID']); + + } //Return result return $return; diff --git a/config/userdata.php b/config/userdata.php index cd05f69..ae2ee22 100644 --- a/config/userdata.php +++ b/config/userdata.php @@ -8,4 +8,9 @@ /** * The subdirectory (of user_data folder) containing image accounts */ -$config->set("imageAccountPath", "avatars/"); \ No newline at end of file +$config->set("imageAccountPath", "avatars/"); + +/** + * The subdirectory (of user_data folder) containing background images + */ +$config->set("backgroundImagePath", "imgfond/"); \ No newline at end of file