From 5e0ed10a74060526fdc4e6a0af8a3047e7943a9a Mon Sep 17 00:00:00 2001 From: Ze'ev Schurmann Date: Thu, 23 May 2024 20:00:44 +0200 Subject: [PATCH] Added ability to hide registration link on login page. Issue #621 Signed-off-by: Ze'ev Schurmann --- lib/Controller/SettingsController.php | 2 ++ lib/RegistrationLoginOption.php | 16 ++++++++++++---- lib/Settings/RegistrationSettings.php | 5 +++++ src/AdminSettings.vue | 12 ++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 4abf2d0e..14741858 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -59,6 +59,7 @@ public function admin(?string $registered_user_group, string $email_verification_hint, string $username_policy_regex, ?bool $admin_approval_required, + ?bool $login_button_hide, ?bool $email_is_optional, ?bool $email_is_login, ?bool $show_fullname, @@ -104,6 +105,7 @@ public function admin(?string $registered_user_group, } $this->config->setAppValue($this->appName, 'admin_approval_required', $admin_approval_required ? 'yes' : 'no'); + $this->config->setAppValue($this->appName, 'login_button_hide', $login_button_hide ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'email_is_optional', $email_is_optional ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'email_is_login', !$email_is_optional && $email_is_login ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'show_fullname', $show_fullname ? 'yes' : 'no'); diff --git a/lib/RegistrationLoginOption.php b/lib/RegistrationLoginOption.php index a2daee39..2c9506b4 100644 --- a/lib/RegistrationLoginOption.php +++ b/lib/RegistrationLoginOption.php @@ -26,24 +26,32 @@ namespace OCA\Registration; use OCP\Authentication\IAlternativeLogin; +use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; class RegistrationLoginOption implements IAlternativeLogin { - public function __construct(protected IURLGenerator $url, protected IL10N $l, protected \OC_Defaults $theming) { + public function __construct(protected IConfig $config, protected IURLGenerator $url, protected IL10N $l, protected \OC_Defaults $theming) { + $this->config = $config; } public function getLabel(): string { - return $this->l->t('Register'); + if ($this->config->getAppValue('registration', 'login_button_hide', 'no') === 'no') { + return $this->l->t('Register'); + } } public function getLink(): string { - return $this->url->linkToRoute('registration.register.showEmailForm'); + if ($this->config->getAppValue('registration', 'login_button_hide', 'no') === 'no') { + return $this->url->linkToRoute('registration.register.showEmailForm'); + } } public function getClass(): string { - return 'register-button'; + if ($this->config->getAppValue('registration', 'login_button_hide', 'no') === 'no') { + return 'register-button'; + } } public function load(): void { diff --git a/lib/Settings/RegistrationSettings.php b/lib/Settings/RegistrationSettings.php index 937187f1..e5e31309 100644 --- a/lib/Settings/RegistrationSettings.php +++ b/lib/Settings/RegistrationSettings.php @@ -54,6 +54,11 @@ public function getForm(): TemplateResponse { $this->config->getAppValue($this->appName, 'admin_approval_required', 'no') === 'yes' ); + $this->initialState->provideInitialState( + 'login_button_hide', + $this->config->getAppValue($this->appName, 'login_button_hide', 'no') === 'yes' + ); + $this->initialState->provideInitialState( 'allowed_domains', $this->config->getAppValue($this->appName, 'allowed_domains') diff --git a/src/AdminSettings.vue b/src/AdminSettings.vue index 71967388..ac5405cc 100644 --- a/src/AdminSettings.vue +++ b/src/AdminSettings.vue @@ -31,6 +31,15 @@

{{ t('registration', 'Enabling "administrator approval" will prevent registrations from mobile and desktop clients to complete as the credentials cannot be verified by the client until the user was enabled.') }}

+ + {{ t('registration', 'Hide registration button on login page') }} + + +

{{ t('registration', 'Enabling, "hide registration button" will ensure the registration button is not displayed on the login page. Instead new users will have to be provided with the registration link, eg. https://nextcloud.domain.tld/index.php/apps/registration/, in order to register.') }}

+