diff --git a/lib/Controller/RegisterController.php b/lib/Controller/RegisterController.php index 45d1f32..bf7e9fe 100644 --- a/lib/Controller/RegisterController.php +++ b/lib/Controller/RegisterController.php @@ -234,9 +234,9 @@ class RegisterController extends Controller { 'email_is_login' => $this->config->getAppValue('registration', 'email_is_login', 'no') === 'yes', 'loginname' => $loginname, 'fullname' => $fullname, - 'show_fullname' => $this->config->getAppValue('registration', 'enfore_fullname', 'no') === 'yes', + 'show_fullname' => $this->config->getAppValue('registration', 'show_fullname', 'no') === 'yes', 'phone' => $phone, - 'show_phone' => $this->config->getAppValue('registration', 'enfore_phone', 'no') === 'yes', + 'show_phone' => $this->config->getAppValue('registration', 'show_phone', 'no') === 'yes', 'message' => $message, 'password' => $password, 'additional_hint' => $additional_hint, diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 66ab814..33ae0f0 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -61,6 +61,10 @@ class SettingsController extends Controller { string $username_policy_regex, ?bool $admin_approval_required, ?bool $email_is_login, + ?bool $show_fullname, + ?bool $enforce_fullname, + ?bool $show_phone, + ?bool $enforce_phone, ?bool $domains_is_blocklist, ?bool $show_domains, ?bool $disable_email_verification) { @@ -101,6 +105,10 @@ class SettingsController extends Controller { $this->config->setAppValue($this->appName, 'admin_approval_required', $admin_approval_required ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'email_is_login', $email_is_login ? 'yes' : 'no'); + $this->config->setAppValue($this->appName, 'show_fullname', $show_fullname ? 'yes' : 'no'); + $this->config->setAppValue($this->appName, 'enforce_fullname', $enforce_fullname ? 'yes' : 'no'); + $this->config->setAppValue($this->appName, 'show_phone', $show_phone ? 'yes' : 'no'); + $this->config->setAppValue($this->appName, 'enforce_phone', $enforce_phone ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'domains_is_blocklist', $domains_is_blocklist ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'show_domains', $show_domains ? 'yes' : 'no'); $this->config->setAppValue($this->appName, 'disable_email_verification', $disable_email_verification ? 'yes' : 'no'); diff --git a/lib/Service/RegistrationService.php b/lib/Service/RegistrationService.php index f453a23..3831dec 100644 --- a/lib/Service/RegistrationService.php +++ b/lib/Service/RegistrationService.php @@ -349,14 +349,17 @@ class RegistrationService { $this->validateUsername($loginName); - if ($this->config->getAppValue('registration', 'enfore_fullname', 'no') === 'yes') { + if ($this->config->getAppValue('registration', 'show_fullname', 'no') === 'yes' + && $this->config->getAppValue('registration', 'enforce_fullname', 'no') === 'yes') { $this->validateDisplayname($fullName); } - if ($phone) { - $this->validatePhoneNumber($phone); - } elseif ($this->config->getAppValue('registration', 'enfore_phone', 'no') === 'yes') { - throw new RegistrationException($this->l10n->t('Please provide a valid phone number.')); + if ($this->config->getAppValue('registration', 'show_phone', 'no') === 'yes') { + if ($phone) { + $this->validatePhoneNumber($phone); + } elseif ($this->config->getAppValue('registration', 'enforce_phone', 'no') === 'yes') { + throw new RegistrationException($this->l10n->t('Please provide a valid phone number.')); + } } /* TODO @@ -381,12 +384,14 @@ class RegistrationService { } // Set display name - if ($fullName) { + if ($fullName && $this->config->getAppValue('registration', 'show_fullname', 'no') === 'yes') { $user->setDisplayName($fullName); } // Set phone number in account data - if (method_exists($this->accountManager, 'updateAccount')) { + if (method_exists($this->accountManager, 'updateAccount') + && $phone + && $this->config->getAppValue('registration', 'show_phone', 'no') === 'yes') { $account = $this->accountManager->getAccount($user); $property = $account->getProperty(IAccountManager::PROPERTY_PHONE); $account->setProperty( diff --git a/lib/Settings/RegistrationSettings.php b/lib/Settings/RegistrationSettings.php index 5036537..edebd13 100644 --- a/lib/Settings/RegistrationSettings.php +++ b/lib/Settings/RegistrationSettings.php @@ -54,13 +54,6 @@ class RegistrationSettings implements ISettings { } public function getForm(): TemplateResponse { - // handle groups - $groups = $this->groupManager->search(''); - $groupIds = []; - foreach ($groups as $group) { - $groupIds[] = $group->getGid(); - } - $this->initialState->provideInitialState( 'registered_user_group', $this->getGroupDetailArray($this->config->getAppValue($this->appName, 'registered_user_group', 'none')) @@ -87,15 +80,35 @@ class RegistrationSettings implements ISettings { 'disable_email_verification', $this->config->getAppValue($this->appName, 'disable_email_verification', 'no') === 'yes' ); + $this->initialState->provideInitialState( 'email_is_login', $this->config->getAppValue($this->appName, 'email_is_login', 'no') === 'yes' ); - $this->initialState->provideInitialState( 'username_policy_regex', $this->config->getAppValue($this->appName, 'username_policy_regex') ); + $this->initialState->provideInitialState( + 'username_policy_regex', + $this->config->getAppValue($this->appName, 'username_policy_regex') + ); + $this->initialState->provideInitialState( + 'show_fullname', + $this->config->getAppValue($this->appName, 'show_fullname', 'no') === 'yes' + ); + $this->initialState->provideInitialState( + 'enforce_fullname', + $this->config->getAppValue($this->appName, 'enforce_fullname', 'no') === 'yes' + ); + $this->initialState->provideInitialState( + 'show_phone', + $this->config->getAppValue($this->appName, 'show_phone', 'no') === 'yes' + ); + $this->initialState->provideInitialState( + 'enforce_phone', + $this->config->getAppValue($this->appName, 'enforce_phone', 'no') === 'yes' + ); $this->initialState->provideInitialState( 'additional_hint', diff --git a/src/AdminSettings.vue b/src/AdminSettings.vue index 1bff2d5..69a8a38 100644 --- a/src/AdminSettings.vue +++ b/src/AdminSettings.vue @@ -39,35 +39,39 @@ +

-

{{ t('registration', 'Email settings') }}

-

{{ domainListLabel }}

- +

+ + +

+
+ +
+

{{ t('registration', 'User settings') }}

-
+ -
-

{{ t('registration', 'Login name settings') }}

- -

{{ t('registration', 'Login name policy') }}

- + @change="saveData"> + +

+ +

+ + +

+ +

+ + +

+ +

+ +

- {{ t('registration', 'If configured, login names will be validated through the regular expression. If the validation fails the user is prompted with a generic error. Make sure your regex is working correctly.') }}
@@ -167,6 +221,7 @@ import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' import axios from '@nextcloud/axios' import { showError, showSuccess } from '@nextcloud/dialogs' +import '@nextcloud/dialogs/styles/toast.scss' import { loadState } from '@nextcloud/initial-state' import { generateOcsUrl, generateUrl } from '@nextcloud/router' import debounce from 'debounce' @@ -182,6 +237,9 @@ export default { return { loading: false, loadingGroups: false, + groups: [], + saveNotification: null, + adminApproval: false, registeredUserGroup: '', allowedDomains: '', @@ -190,9 +248,12 @@ export default { disableEmailVerification: false, emailIsLogin: false, usernamePolicyRegex: '', + showFullname: false, + enforceFullname: false, + showPhone: false, + enforcePhone: false, additionalHint: '', emailVerificationHint: '', - groups: [], } }, @@ -222,6 +283,10 @@ export default { this.disableEmailVerification = loadState('registration', 'disable_email_verification') this.emailIsLogin = loadState('registration', 'email_is_login') this.usernamePolicyRegex = loadState('registration', 'username_policy_regex') + this.showFullname = loadState('registration', 'show_fullname') + this.enforceFullname = loadState('registration', 'enforce_fullname') + this.showPhone = loadState('registration', 'show_phone') + this.enforcePhone = loadState('registration', 'enforce_phone') this.additionalHint = loadState('registration', 'additional_hint') this.emailVerificationHint = loadState('registration', 'email_verification_hint') @@ -234,6 +299,10 @@ export default { async saveData() { this.loading = true + if (this.saveNotification) { + await this.saveNotification.hideToast() + } + try { const response = await axios.post(generateUrl('/apps/registration/settings'), { admin_approval_required: this.adminApproval, @@ -244,22 +313,26 @@ export default { disable_email_verification: this.disableEmailVerification, email_is_login: this.emailIsLogin, username_policy_regex: this.usernamePolicyRegex, + show_fullname: this.showFullname, + enforce_fullname: this.enforceFullname, + show_phone: this.showPhone, + enforce_phone: this.enforcePhone, additional_hint: this.additionalHint, email_verification_hint: this.emailVerificationHint, }) if (response?.data?.status === 'success' && response?.data?.data?.message) { - showSuccess(response.data.data.message) + this.saveNotification = showSuccess(response.data.data.message) } else if (response?.data?.data?.message) { - showError(response.data.data.message) + this.saveNotification = showError(response.data.data.message) } else { - showError(t('registration', 'An error occurred while saving the settings')) + this.saveNotification = showError(t('registration', 'An error occurred while saving the settings')) } } catch (e) { if (e.response?.data?.data?.message) { - showError(e.response.data.data.message) + this.saveNotification = showError(e.response.data.data.message) } else { - showError(t('registration', 'An error occurred while saving the settings')) + this.saveNotification = showError(t('registration', 'An error occurred while saving the settings')) console.error(e) } } @@ -287,3 +360,17 @@ export default { }, } + +