User authentication configuration
authorMarcel Werk <burntime@woltlab.com>
Wed, 13 Dec 2023 13:43:40 +0000 (14:43 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 26 Mar 2024 12:30:32 +0000 (13:30 +0100)
A central location for the configuration should make it easier to disable certain unwanted functions in SSO plugins.

wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php b/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfiguration.class.php
new file mode 100644 (file)
index 0000000..1f3f27b
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+
+namespace wcf\system\user\authentication\configuration;
+
+/**
+ * Represents the configuration of the user authentication process.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license     WoltLab License <http://www.woltlab.com/license-agreement.html>
+ */
+final class UserAuthenticationConfiguration
+{
+    public function __construct(
+        public readonly bool $canRegister = true,
+        public readonly bool $canLogin = true,
+        public readonly bool $canChangeUsername = true,
+        public readonly bool $canChangeEmail = true,
+        public readonly bool $canChangePassword = true,
+    ) {
+    }
+}
diff --git a/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php b/wcfsetup/install/files/lib/system/user/authentication/configuration/UserAuthenticationConfigurationFactory.class.php
new file mode 100644 (file)
index 0000000..51e1433
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+namespace wcf\system\user\authentication\configuration;
+
+use wcf\system\appmaker\app\preset\event\ConfigurationLoading;
+use wcf\system\event\EventHandler;
+use wcf\system\SingletonFactory;
+
+/**
+ * Provides the instance of the active configuration of the user authentication process.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license     WoltLab License <http://www.woltlab.com/license-agreement.html>
+ */
+final class UserAuthenticationConfigurationFactory extends SingletonFactory
+{
+    private UserAuthenticationConfiguration $configuration;
+
+    #[\Override]
+    protected function init()
+    {
+        $this->configuration = $this->getDefaultConfiguration();
+
+        $event = new ConfigurationLoading();
+        EventHandler::getInstance()->fire($event);
+        if ($event->getConfigration()) {
+            $this->configuration = $event->getConfigration();
+        }
+    }
+
+    public function getConfigration(): UserAuthenticationConfiguration
+    {
+        return $this->configuration;
+    }
+
+    private function getDefaultConfiguration(): UserAuthenticationConfiguration
+    {
+        return new UserAuthenticationConfiguration(
+            !\REGISTER_DISABLED,
+        );
+    }
+}
diff --git a/wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php b/wcfsetup/install/files/lib/system/user/authentication/configuration/event/ConfigurationLoading.class.php
new file mode 100644 (file)
index 0000000..eba6168
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+namespace wcf\system\appmaker\app\preset\event;
+
+use wcf\system\event\IEvent;
+use wcf\system\user\authentication\configuration\UserAuthenticationConfiguration;
+
+/**
+ * Indicates the loading of the configuration.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license     WoltLab License <http://www.woltlab.com/license-agreement.html>
+ */
+final class ConfigurationLoading implements IEvent
+{
+    private UserAuthenticationConfiguration $configuration;
+
+    public function register(UserAuthenticationConfiguration $configuration): void
+    {
+        if (isset($this->configuration)) {
+            throw new \BadMethodCallException("A configuration has already been loaded");
+        }
+
+        $this->configuration = $configuration;
+    }
+
+    public function getConfigration(): ?UserAuthenticationConfiguration
+    {
+        return $this->configuration ?? null;
+    }
+}