Can check the availability of a domain.

This commit is contained in:
Pierre 2018-04-17 19:16:10 +02:00
parent 37d21ee6c3
commit e22205e91e
3 changed files with 44 additions and 1 deletions

View File

@ -28,6 +28,27 @@ class SettingsController {
} }
/**
* Check the availability of a user directory
*
* @url POST /settings/check_user_directory_availability
*/
public function checkUserDirectoryAvailability() {
//User login needed
user_login_required();
//Get user directory
$userDirectory = getPostUserDirectory("directory");
//Check if the directory is available
if(!components()->settings->checkUserDirectoryAvailability($userDirectory, userID))
Rest_fatal_error(401, "The specified domain is not available!");
//Else the domain is available
return array("success" => "The domain is available!");
}
/** /**
* Turn a GeneralSettings object into a valid API object * Turn a GeneralSettings object into a valid API object
* *

View File

@ -27,6 +27,28 @@ class SettingsComponents {
return $this->dbToGeneralSettings($entry); return $this->dbToGeneralSettings($entry);
} }
/**
* Check whether a directory is already linked to a user or not. If yes,
* check if it linked to a specified user ID.
*
* @param string $directory The directory to check
* @param int $userID Target user ID
* @return bool TRUE if the directory is available for the current user,
* FALSE else
*/
public function checkUserDirectoryAvailability(string $directory, int $userID) : bool {
//Redirect the request to the user component
$folderUserID = components()->user->findByFolder($directory);
//Check if the folder is available
if($folderUserID == 0)
return TRUE;
//Check else if the user is owning this domain or not
return $folderUserID == $userID;
}
/** /**
* Get Single User Infos from database and return its information as an array * Get Single User Infos from database and return its information as an array
* *

View File

@ -485,6 +485,6 @@ function getPostUserDirectory(string $name) : string {
Rest_fatal_error(401, "Specified directory seems to be invalid!"); Rest_fatal_error(401, "Specified directory seems to be invalid!");
//Return the directory //Return the directory
return $name; return $directory;
} }