public function setup() { $this->addService("registration", "RegistrationServices"); $this->env->features()->addFeature("registration"); RegistrationEvent::register($this->env->events()); $this->env->permissions()->registerPermission("manage_user_registrations"); }
private function createUser($registration) { $db = $this->env->db(); $plugin = $this->env->plugins()->getPlugin("Registration"); $permission = $plugin->getSetting("permission", Authentication::PERMISSION_VALUE_READONLY); $lang = $this->getPluginSetting("language", NULL); $id = $this->env->configuration()->addUser($registration['name'], $lang, $registration['email'], $permission, NULL); $this->env->configuration()->storeUserAuth($id, $registration['name'], NULL, $registration['password']); $db->update("DELETE from " . $db->table("registration") . " where `id`=" . $db->string($registration['id'], TRUE)); $this->addUserProperties($id, $registration['name'], $plugin); //if (file_exists("plugin/Registration/custom/CustomRegistrationHandler.php")) include("custom/CustomRegistrationHandler.php"); //if (function_exists("onConfirmCustomData")) onConfirmCustomData($registration, $id); $this->env->events()->onEvent(RegistrationEvent::userCreated($id, $registration['name'])); }
public function setup() { $this->addService("registration", "RegistrationServices"); $this->env->features()->addFeature("registration"); RegistrationEvent::register($this->env->events()); }
private function addUserProperties($id, $registration, $plugin) { $name = $registration["name"]; $groups = $plugin->getSetting("groups", array()); if (count($groups) > 0) { $existing = array(); foreach ($this->env->configuration()->getAllUserGroups() as $group) { if (in_array($group['id'], $groups)) { $existing[] = $group['id']; } } if (count($existing) > 0) { $this->env->configuration()->addUsersGroups($id, $existing); } } $permissions = $plugin->getSetting("permissions", NULL); // add user default/generic permissions if ($permissions != NULL) { if (!is_array($permissions)) { $permissions = array("filesystem_item_access" => $permissions); } Logging::logDebug("Setting user permissions: " . Util::array2str($permissions)); foreach ($permissions as $pk => $pv) { //TODO validate permission key (pv) and value (pv) $this->env->permissions()->addGenericPermission($pk, $id, $pv); } } $folders = $plugin->getSetting("folders", array()); $folderIds = array(); $folderProps = array(); if (Util::isAssocArray($folders)) { $folderIds = array_keys($folders); $folderProps = $folders; } else { $folderIds = $folders; } if (count($folderIds) > 0) { $existing = array(); foreach ($this->env->configuration()->getFolders() as $folder) { if (in_array($folder['id'], $folderIds)) { $existing[] = $folder['id']; } } if (count($existing) > 0) { //$this->env->configuration()->addUserFolders($id, $existing); foreach ($existing as $f) { $fname = NULL; $fp = array_key_exists($f, $folderProps) ? $folderProps[$f] : array(); if (array_key_exists("name", $fp)) { $fname = $fp["name"]; } Logging::logDebug("Assigning user folder: " . $f . " (" . $fname . ")"); $this->env->configuration()->addUserFolder($id, $f, $fname); // add folder permissions if (array_key_exists("permissions", $fp)) { $fs = $this->env->filesystem()->filesystem($this->env->configuration()->getFolder($f)); $permissions = $fp["permissions"]; if (!is_array($permissions)) { $permissions = array("filesystem_item_access" => $permissions); } Logging::logDebug("Setting folder " . $f . " permissions: " . Util::array2str($permissions)); foreach ($permissions as $pk => $pv) { //TODO validate permission key (pv) and value (pv) $this->env->permissions()->addFilesystemPermission($fs->root(), $pk, $id, $pv); } } } } } $userFolder = $plugin->getSetting("user_folder", NULL); if ($userFolder == NULL) { return; } // automatic user folder if (!isset($userFolder["path"])) { Logging::logError("Registration: missing configuration for user folder"); return; } $basePath = $userFolder["path"]; $folderName = $name; if (isset($userFolder["folder_name"])) { $folderName = $userFolder["folder_name"]; } $folderPath = rtrim($basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $name; $type = "local"; $uf = array("type" => $type, "path" => $folderPath, "name" => $folderName); Logging::logDebug("Creating user folder " . Util::array2str($uf)); $fs = $this->env->filesystem()->filesystem($uf, FALSE); if ($fs->exists()) { Logging::logError("Registration: user folder [" . $folderPath . "] already exists, not added"); return; } if (!$fs->create()) { Logging::logError("Registration: user folder [" . $folderPath . "] could not be created, not added"); return; } $uf["id"] = $this->env->configuration()->addFolder($name, $folderPath); $this->env->configuration()->addUserFolder($id, $uf["id"], $uf["name"]); $fs = $this->env->filesystem()->filesystem($uf, FALSE); $fsroot = $fs->root(); // add user folder permissions $permissions = array(); if (isset($userFolder["permissions"])) { $permissions = $userFolder["permissions"]; if (!is_array($permissions)) { $permissions = array("filesystem_item_access" => $permissions); } } else { $permissions = array("filesystem_item_access" => FilesystemController::PERMISSION_LEVEL_READWRITEDELETE); } Logging::logDebug("Setting user folder permissions: " . Util::array2str($permissions)); foreach ($permissions as $pk => $pv) { //TODO validate permission key (pv) and value (pv) $this->env->permissions()->addFilesystemPermission($fsroot, $pk, $id, $pv); } // assign folder to other users if (isset($userFolder["add_to_users"]) and count($userFolder["add_to_users"]) > 0) { $users = $userFolder["add_to_users"]; $existing = array(); foreach ($this->env->configuration()->getAllUsers() as $user) { if (in_array($user['id'], $users)) { $existing[] = $user['id']; } } if (count($existing) > 0) { $this->env->configuration()->addFolderUsers($uf["id"], $existing); } } $this->env->events()->onEvent(RegistrationEvent::userFolderCreated($id, $registration['name'], $registration['email'], $registration["id"], $fsroot)); }