Skip to content

Commit

Permalink
Added ability to hide registration link on login page.
Browse files Browse the repository at this point in the history
Signed-off-by: Ze'ev Schurmann <[email protected]> <[email protected]>
  • Loading branch information
thisiszeev committed Apr 12, 2024
1 parent 08e4691 commit e73f50f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## Changes by Ze'ev Schurmann
### Added
- Added ability to hide registration link on login page
[#621](https://github.com/nextcloud/registration/issues/621)

## 2.4.0 - 2024-03-13

### Added
Expand Down
4 changes: 4 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function admin(?string $registered_user_group,
string $email_verification_hint,
string $username_policy_regex,
?bool $admin_approval_required,
// Define login_button_hide as boolean (thisiszeev)
?bool $login_button_hide,
?bool $email_is_optional,
?bool $email_is_login,
?bool $show_fullname,
Expand Down Expand Up @@ -104,6 +106,8 @@ public function admin(?string $registered_user_group,
}

$this->config->setAppValue($this->appName, 'admin_approval_required', $admin_approval_required ? 'yes' : 'no');
// Define values for login_button_hide. (thisiszeev)
$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');
Expand Down
19 changes: 15 additions & 4 deletions lib/RegistrationLoginOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@
use OCP\Authentication\IAlternativeLogin;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IConfig;

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');
// Decide if login page will display registration link (thisiszeev)
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');
// Decide if login page will display registration link (thisiszeev)
if ($this->config->getAppValue('registration', 'login_button_hide', 'no') === 'no') {
return $this->url->linkToRoute('registration.register.showEmailForm');
}
}

public function getClass(): string {
return 'register-button';
// Decide if login page will display registration link (thisiszeev)
if ($this->config->getAppValue('registration', 'login_button_hide', 'no') === 'no') {
return 'register-button';
}
}

public function load(): void {
Expand Down
6 changes: 6 additions & 0 deletions lib/Settings/RegistrationSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public function getForm(): TemplateResponse {
$this->config->getAppValue($this->appName, 'admin_approval_required', 'no') === 'yes'
);

// Define values for Admin Page (thisiszeev)
$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')
Expand Down
16 changes: 16 additions & 0 deletions src/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@

<p><em>{{ 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.') }}</em></p>

<!-- Draw elements on Admin Page for loginButtonHide (thisiszeev) -->

Check failure on line 34 in src/AdminSettings.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 0 tabs
<NcCheckboxRadioSwitch :checked.sync="loginButtonHide"

Check failure on line 35 in src/AdminSettings.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Expected indentation of 3 tabs but found 2 tabs
type="switch"
:disabled="loading"
@update:checked="saveData">
{{ t('registration', 'Hide registration button on login page') }}
</NcCheckboxRadioSwitch>

<p><em>{{ 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.') }}</em></p>

<div>
<div class="margin-top">
<label for="registered_user_group">
Expand Down Expand Up @@ -203,6 +213,8 @@ export default {
saveNotification: null,
adminApproval: false,
// Default value for loginButtonHide (thisiszeev)
loginButtonHide: false,
registeredUserGroup: '',
allowedDomains: '',
domainsIsBlocklist: false,
Expand Down Expand Up @@ -239,6 +251,8 @@ export default {
mounted() {
this.adminApproval = loadState('registration', 'admin_approval_required')
// (thisiszeev)
this.loginButtonHide = loadState('registration', 'login_button_hide')
this.registeredUserGroup = loadState('registration', 'registered_user_group')
this.allowedDomains = loadState('registration', 'allowed_domains')
this.domainsIsBlocklist = loadState('registration', 'domains_is_blocklist')
Expand Down Expand Up @@ -270,6 +284,8 @@ export default {
try {
const response = await axios.post(generateUrl('/apps/registration/settings'), {
admin_approval_required: this.adminApproval,
// (thisiszeev)
login_button_hide: this.loginButtonHide,
registered_user_group: this.registeredUserGroup?.id,
allowed_domains: this.allowedDomains,
domains_is_blocklist: this.domainsIsBlocklist,
Expand Down

0 comments on commit e73f50f

Please sign in to comment.