Add new admin settings to show/enforce fullname/phone
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
d34e6c20de
commit
8ef7b52c19
|
|
@ -234,9 +234,9 @@ class RegisterController extends Controller {
|
||||||
'email_is_login' => $this->config->getAppValue('registration', 'email_is_login', 'no') === 'yes',
|
'email_is_login' => $this->config->getAppValue('registration', 'email_is_login', 'no') === 'yes',
|
||||||
'loginname' => $loginname,
|
'loginname' => $loginname,
|
||||||
'fullname' => $fullname,
|
'fullname' => $fullname,
|
||||||
'show_fullname' => $this->config->getAppValue('registration', 'enfore_fullname', 'no') === 'yes',
|
'show_fullname' => $this->config->getAppValue('registration', 'show_fullname', 'no') === 'yes',
|
||||||
'phone' => $phone,
|
'phone' => $phone,
|
||||||
'show_phone' => $this->config->getAppValue('registration', 'enfore_phone', 'no') === 'yes',
|
'show_phone' => $this->config->getAppValue('registration', 'show_phone', 'no') === 'yes',
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'additional_hint' => $additional_hint,
|
'additional_hint' => $additional_hint,
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ class SettingsController extends Controller {
|
||||||
string $username_policy_regex,
|
string $username_policy_regex,
|
||||||
?bool $admin_approval_required,
|
?bool $admin_approval_required,
|
||||||
?bool $email_is_login,
|
?bool $email_is_login,
|
||||||
|
?bool $show_fullname,
|
||||||
|
?bool $enforce_fullname,
|
||||||
|
?bool $show_phone,
|
||||||
|
?bool $enforce_phone,
|
||||||
?bool $domains_is_blocklist,
|
?bool $domains_is_blocklist,
|
||||||
?bool $show_domains,
|
?bool $show_domains,
|
||||||
?bool $disable_email_verification) {
|
?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, '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, '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, 'domains_is_blocklist', $domains_is_blocklist ? 'yes' : 'no');
|
||||||
$this->config->setAppValue($this->appName, 'show_domains', $show_domains ? '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');
|
$this->config->setAppValue($this->appName, 'disable_email_verification', $disable_email_verification ? 'yes' : 'no');
|
||||||
|
|
|
||||||
|
|
@ -349,14 +349,17 @@ class RegistrationService {
|
||||||
|
|
||||||
$this->validateUsername($loginName);
|
$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);
|
$this->validateDisplayname($fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($phone) {
|
if ($this->config->getAppValue('registration', 'show_phone', 'no') === 'yes') {
|
||||||
$this->validatePhoneNumber($phone);
|
if ($phone) {
|
||||||
} elseif ($this->config->getAppValue('registration', 'enfore_phone', 'no') === 'yes') {
|
$this->validatePhoneNumber($phone);
|
||||||
throw new RegistrationException($this->l10n->t('Please provide a valid phone number.'));
|
} elseif ($this->config->getAppValue('registration', 'enforce_phone', 'no') === 'yes') {
|
||||||
|
throw new RegistrationException($this->l10n->t('Please provide a valid phone number.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
|
|
@ -381,12 +384,14 @@ class RegistrationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set display name
|
// Set display name
|
||||||
if ($fullName) {
|
if ($fullName && $this->config->getAppValue('registration', 'show_fullname', 'no') === 'yes') {
|
||||||
$user->setDisplayName($fullName);
|
$user->setDisplayName($fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set phone number in account data
|
// 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);
|
$account = $this->accountManager->getAccount($user);
|
||||||
$property = $account->getProperty(IAccountManager::PROPERTY_PHONE);
|
$property = $account->getProperty(IAccountManager::PROPERTY_PHONE);
|
||||||
$account->setProperty(
|
$account->setProperty(
|
||||||
|
|
|
||||||
|
|
@ -54,13 +54,6 @@ class RegistrationSettings implements ISettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getForm(): TemplateResponse {
|
public function getForm(): TemplateResponse {
|
||||||
// handle groups
|
|
||||||
$groups = $this->groupManager->search('');
|
|
||||||
$groupIds = [];
|
|
||||||
foreach ($groups as $group) {
|
|
||||||
$groupIds[] = $group->getGid();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->initialState->provideInitialState(
|
$this->initialState->provideInitialState(
|
||||||
'registered_user_group',
|
'registered_user_group',
|
||||||
$this->getGroupDetailArray($this->config->getAppValue($this->appName, 'registered_user_group', 'none'))
|
$this->getGroupDetailArray($this->config->getAppValue($this->appName, 'registered_user_group', 'none'))
|
||||||
|
|
@ -87,15 +80,35 @@ class RegistrationSettings implements ISettings {
|
||||||
'disable_email_verification',
|
'disable_email_verification',
|
||||||
$this->config->getAppValue($this->appName, 'disable_email_verification', 'no') === 'yes'
|
$this->config->getAppValue($this->appName, 'disable_email_verification', 'no') === 'yes'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->initialState->provideInitialState(
|
$this->initialState->provideInitialState(
|
||||||
'email_is_login',
|
'email_is_login',
|
||||||
$this->config->getAppValue($this->appName, 'email_is_login', 'no') === 'yes'
|
$this->config->getAppValue($this->appName, 'email_is_login', 'no') === 'yes'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->initialState->provideInitialState(
|
$this->initialState->provideInitialState(
|
||||||
'username_policy_regex',
|
'username_policy_regex',
|
||||||
$this->config->getAppValue($this->appName, '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(
|
$this->initialState->provideInitialState(
|
||||||
'additional_hint',
|
'additional_hint',
|
||||||
|
|
|
||||||
|
|
@ -39,35 +39,39 @@
|
||||||
<label for="registered_user_group">
|
<label for="registered_user_group">
|
||||||
{{ t('registration', 'Registered users default group') }}
|
{{ t('registration', 'Registered users default group') }}
|
||||||
</label>
|
</label>
|
||||||
|
<Multiselect
|
||||||
|
id="registered_user_group"
|
||||||
|
v-model="registeredUserGroup"
|
||||||
|
:placeholder="t('registration', 'Select group')"
|
||||||
|
:options="groups"
|
||||||
|
:disabled="loading"
|
||||||
|
:searchable="true"
|
||||||
|
:tag-width="60"
|
||||||
|
:loading="loadingGroups"
|
||||||
|
:allow-empty="true"
|
||||||
|
:close-on-select="false"
|
||||||
|
track-by="id"
|
||||||
|
label="displayname"
|
||||||
|
@search-change="searchGroup"
|
||||||
|
@change="saveData" />
|
||||||
</p>
|
</p>
|
||||||
<Multiselect
|
|
||||||
id="registered_user_group"
|
|
||||||
v-model="registeredUserGroup"
|
|
||||||
:placeholder="t('registration', 'Select group')"
|
|
||||||
:options="groups"
|
|
||||||
:disabled="loading"
|
|
||||||
:searchable="true"
|
|
||||||
:tag-width="60"
|
|
||||||
:loading="loadingGroups"
|
|
||||||
:allow-empty="true"
|
|
||||||
:close-on-select="false"
|
|
||||||
track-by="id"
|
|
||||||
label="displayname"
|
|
||||||
@search-change="searchGroup"
|
|
||||||
@change="saveData" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h2>{{ t('registration', 'Email settings') }}</h2>
|
<h2>{{ t('registration', 'Email settings') }}</h2>
|
||||||
|
|
||||||
<h4>{{ domainListLabel }}</h4>
|
<p>
|
||||||
<input v-model="allowedDomains"
|
<label for="allowed_domains">{{ domainListLabel }}</label>
|
||||||
type="text"
|
<input
|
||||||
name="allowed_domains"
|
id="allowed_domains"
|
||||||
:disabled="loading"
|
v-model="allowedDomains"
|
||||||
placeholder="nextcloud.com;*.example.com"
|
type="text"
|
||||||
:aria-label="t('registration', 'Allowed email domain')"
|
name="allowed_domains"
|
||||||
@input="debounceSavingSlow">
|
:disabled="loading"
|
||||||
|
placeholder="nextcloud.com;*.example.com"
|
||||||
|
:aria-label="t('registration', 'Allowed email domain')"
|
||||||
|
@input="debounceSavingSlow">
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<input id="domains_is_blocklist"
|
<input id="domains_is_blocklist"
|
||||||
|
|
@ -101,6 +105,10 @@
|
||||||
@change="saveData">
|
@change="saveData">
|
||||||
<label for="disable_email_verification">{{ t('registration', 'Disable email verification') }}</label>
|
<label for="disable_email_verification">{{ t('registration', 'Disable email verification') }}</label>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="section">
|
||||||
|
<h2>{{ t('registration', 'User settings') }}</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<input id="email_is_login"
|
<input id="email_is_login"
|
||||||
|
|
@ -112,24 +120,70 @@
|
||||||
@change="saveData">
|
@change="saveData">
|
||||||
<label for="email_is_login">{{ t('registration', 'Force email as login name') }}</label>
|
<label for="email_is_login">{{ t('registration', 'Force email as login name') }}</label>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
<template
|
||||||
|
v-if="!emailIsLogin">
|
||||||
|
<p>
|
||||||
|
<label for="username_policy_regex">{{ t('registration', 'Login name policy') }}</label>
|
||||||
|
<input
|
||||||
|
id="username_policy_regex"
|
||||||
|
v-model="usernamePolicyRegex"
|
||||||
|
type="text"
|
||||||
|
name="username_policy_regex"
|
||||||
|
:disabled="loading"
|
||||||
|
placeholder="E.g.: /^[a-z-]+\.[a-z-]+$/"
|
||||||
|
:aria-label="t('registration', 'Regular expression to validate login names')"
|
||||||
|
@input="debounceSavingSlow">
|
||||||
|
</p>
|
||||||
|
<em>{{ 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.') }}</em>
|
||||||
|
</template>
|
||||||
|
|
||||||
<div
|
|
||||||
v-if="!emailIsLogin"
|
|
||||||
class="section">
|
|
||||||
<h2>{{ t('registration', 'Login name settings') }}</h2>
|
|
||||||
|
|
||||||
<h3>{{ t('registration', 'Login name policy') }}</h3>
|
|
||||||
<p>
|
<p>
|
||||||
<input v-model="usernamePolicyRegex"
|
<input id="show_fullname"
|
||||||
type="text"
|
v-model="showFullname"
|
||||||
name="username_policy_regex"
|
type="checkbox"
|
||||||
|
name="show_fullname"
|
||||||
|
class="checkbox"
|
||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
placeholder="E.g.: /^[a-z-]+\.[a-z-]+$/"
|
@change="saveData">
|
||||||
:aria-label="t('registration', 'Regular expression to validate login names')"
|
<label for="show_fullname">{{ t('registration', 'Show full name field') }}</label>
|
||||||
@input="debounceSavingSlow">
|
</p>
|
||||||
|
|
||||||
|
<p
|
||||||
|
v-if="showFullname"
|
||||||
|
class="indent">
|
||||||
|
<input id="enforce_fullname"
|
||||||
|
v-model="enforceFullname"
|
||||||
|
type="checkbox"
|
||||||
|
name="enforce_fullname"
|
||||||
|
class="checkbox"
|
||||||
|
:disabled="loading"
|
||||||
|
@change="saveData">
|
||||||
|
<label for="enforce_fullname">{{ t('registration', 'Enforce full name field') }}</label>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input id="show_phone"
|
||||||
|
v-model="showPhone"
|
||||||
|
type="checkbox"
|
||||||
|
name="show_phone"
|
||||||
|
class="checkbox"
|
||||||
|
:disabled="loading"
|
||||||
|
@change="saveData">
|
||||||
|
<label for="show_phone">{{ t('registration', 'Show phone field') }}</label>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p
|
||||||
|
v-if="showPhone"
|
||||||
|
class="indent">
|
||||||
|
<input id="enforce_phone"
|
||||||
|
v-model="enforcePhone"
|
||||||
|
type="checkbox"
|
||||||
|
name="enforce_phone"
|
||||||
|
class="checkbox"
|
||||||
|
:disabled="loading"
|
||||||
|
@change="saveData">
|
||||||
|
<label for="enforce_phone">{{ t('registration', 'Enforce phone field') }}</label>
|
||||||
</p>
|
</p>
|
||||||
<em>{{ 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.') }}</em>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
|
|
@ -167,6 +221,7 @@
|
||||||
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
|
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
|
||||||
import axios from '@nextcloud/axios'
|
import axios from '@nextcloud/axios'
|
||||||
import { showError, showSuccess } from '@nextcloud/dialogs'
|
import { showError, showSuccess } from '@nextcloud/dialogs'
|
||||||
|
import '@nextcloud/dialogs/styles/toast.scss'
|
||||||
import { loadState } from '@nextcloud/initial-state'
|
import { loadState } from '@nextcloud/initial-state'
|
||||||
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
|
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
|
||||||
import debounce from 'debounce'
|
import debounce from 'debounce'
|
||||||
|
|
@ -182,6 +237,9 @@ export default {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingGroups: false,
|
loadingGroups: false,
|
||||||
|
groups: [],
|
||||||
|
saveNotification: null,
|
||||||
|
|
||||||
adminApproval: false,
|
adminApproval: false,
|
||||||
registeredUserGroup: '',
|
registeredUserGroup: '',
|
||||||
allowedDomains: '',
|
allowedDomains: '',
|
||||||
|
|
@ -190,9 +248,12 @@ export default {
|
||||||
disableEmailVerification: false,
|
disableEmailVerification: false,
|
||||||
emailIsLogin: false,
|
emailIsLogin: false,
|
||||||
usernamePolicyRegex: '',
|
usernamePolicyRegex: '',
|
||||||
|
showFullname: false,
|
||||||
|
enforceFullname: false,
|
||||||
|
showPhone: false,
|
||||||
|
enforcePhone: false,
|
||||||
additionalHint: '',
|
additionalHint: '',
|
||||||
emailVerificationHint: '',
|
emailVerificationHint: '',
|
||||||
groups: [],
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -222,6 +283,10 @@ export default {
|
||||||
this.disableEmailVerification = loadState('registration', 'disable_email_verification')
|
this.disableEmailVerification = loadState('registration', 'disable_email_verification')
|
||||||
this.emailIsLogin = loadState('registration', 'email_is_login')
|
this.emailIsLogin = loadState('registration', 'email_is_login')
|
||||||
this.usernamePolicyRegex = loadState('registration', 'username_policy_regex')
|
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.additionalHint = loadState('registration', 'additional_hint')
|
||||||
this.emailVerificationHint = loadState('registration', 'email_verification_hint')
|
this.emailVerificationHint = loadState('registration', 'email_verification_hint')
|
||||||
|
|
||||||
|
|
@ -234,6 +299,10 @@ export default {
|
||||||
|
|
||||||
async saveData() {
|
async saveData() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
|
if (this.saveNotification) {
|
||||||
|
await this.saveNotification.hideToast()
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(generateUrl('/apps/registration/settings'), {
|
const response = await axios.post(generateUrl('/apps/registration/settings'), {
|
||||||
admin_approval_required: this.adminApproval,
|
admin_approval_required: this.adminApproval,
|
||||||
|
|
@ -244,22 +313,26 @@ export default {
|
||||||
disable_email_verification: this.disableEmailVerification,
|
disable_email_verification: this.disableEmailVerification,
|
||||||
email_is_login: this.emailIsLogin,
|
email_is_login: this.emailIsLogin,
|
||||||
username_policy_regex: this.usernamePolicyRegex,
|
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,
|
additional_hint: this.additionalHint,
|
||||||
email_verification_hint: this.emailVerificationHint,
|
email_verification_hint: this.emailVerificationHint,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response?.data?.status === 'success' && response?.data?.data?.message) {
|
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) {
|
} else if (response?.data?.data?.message) {
|
||||||
showError(response.data.data.message)
|
this.saveNotification = showError(response.data.data.message)
|
||||||
} else {
|
} 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) {
|
} catch (e) {
|
||||||
if (e.response?.data?.data?.message) {
|
if (e.response?.data?.data?.message) {
|
||||||
showError(e.response.data.data.message)
|
this.saveNotification = showError(e.response.data.data.message)
|
||||||
} else {
|
} 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)
|
console.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -287,3 +360,17 @@ export default {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
|
||||||
|
p {
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.indent {
|
||||||
|
padding-left: 28px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue