Add admin UI option for "Force email as user id"

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-08-28 18:15:21 +02:00
parent 69197003a2
commit a9246921f0
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
5 changed files with 28 additions and 11 deletions

View File

@ -7,3 +7,7 @@ select {
h3 { h3 {
margin-top: 25px; margin-top: 25px;
} }
p {
margin-top: 15px;
}

View File

@ -194,7 +194,7 @@ class RegisterController extends Controller {
return new TemplateResponse('registration', 'form/user', [ return new TemplateResponse('registration', 'form/user', [
'email' => $registration->getEmail(), 'email' => $registration->getEmail(),
'email_is_login' => $this->config->getAppValue('registration', 'email_is_login', '0') === '1', 'email_is_login' => $this->config->getAppValue('registration', 'email_is_login', 'no') === 'yes',
'username' => $username, 'username' => $username,
'message' => $message, 'message' => $message,
], 'guest'); ], 'guest');
@ -218,7 +218,7 @@ class RegisterController extends Controller {
return $this->validateSecretAndTokenErrorPage(); return $this->validateSecretAndTokenErrorPage();
} }
if ($this->config->getAppValue('registration', 'email_is_login', '0') === '1') { if ($this->config->getAppValue('registration', 'email_is_login', 'no') === 'yes') {
$username = $registration->getEmail(); $username = $registration->getEmail();
} }

View File

@ -44,10 +44,11 @@ class SettingsController extends Controller {
* *
* @param string $registered_user_group all newly registered user will be put in this group * @param string $registered_user_group all newly registered user will be put in this group
* @param string $allowed_domains Registrations are only allowed for E-Mailadresses with these domains * @param string $allowed_domains Registrations are only allowed for E-Mailadresses with these domains
* @param bool $admin_approval_required newly registered users have to be validated by an admin * @param bool|null $admin_approval_required newly registered users have to be validated by an admin
* @param bool|null $email_is_login email address is forced as user id
* @return DataResponse * @return DataResponse
*/ */
public function admin($registered_user_group, $allowed_domains, $admin_approval_required) { public function admin(string $registered_user_group, string $allowed_domains, ?bool $admin_approval_required, ?bool $email_is_login) {
// handle domains // handle domains
if (($allowed_domains === '') || ($allowed_domains === null)) { if (($allowed_domains === '') || ($allowed_domains === null)) {
$this->config->deleteAppValue($this->appName, 'allowed_domains'); $this->config->deleteAppValue($this->appName, 'allowed_domains');
@ -56,7 +57,10 @@ class SettingsController extends Controller {
} }
// handle admin validation // handle admin validation
$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');
// handle email is login
$this->config->setAppValue($this->appName, 'email_is_login', $email_is_login ? 'yes' : 'no');
// handle groups // handle groups
$groups = $this->groupmanager->search(''); $groups = $this->groupmanager->search('');

View File

@ -60,13 +60,17 @@ class RegistrationSettings implements ISettings {
$allowedDomains = $this->config->getAppValue($this->appName, 'allowed_domains', ''); $allowedDomains = $this->config->getAppValue($this->appName, 'allowed_domains', '');
// handle admin validation // handle admin validation
$adminApprovalRequired = $this->config->getAppValue($this->appName, 'admin_approval_required', "no"); $adminApprovalRequired = $this->config->getAppValue($this->appName, 'admin_approval_required', 'no');
// handle admin validation
$emailIsLogin = $this->config->getAppValue($this->appName, 'email_is_login', 'no');
return new TemplateResponse('registration', 'admin', [ return new TemplateResponse('registration', 'admin', [
'groups' => $groupIds, 'groups' => $groupIds,
'current' => $assignedGroups, 'current' => $assignedGroups,
'allowed' => $allowedDomains, 'allowed' => $allowedDomains,
'approval_required' => $adminApprovalRequired 'approval_required' => $adminApprovalRequired,
'email_is_login' => $emailIsLogin,
], ''); ], '');
} }

View File

@ -28,14 +28,19 @@ foreach ($_['groups'] as $group) {
<input type="text" id="allowed_domains" name="allowed_domains" value="<?php p($_['allowed']);?>" placeholder="nextcloud.com;*.example.com"> <input type="text" id="allowed_domains" name="allowed_domains" value="<?php p($_['allowed']);?>" placeholder="nextcloud.com;*.example.com">
</label> </label>
</p> </p>
<p>
<em><?php p($l->t('Enter a semicolon-separated list of allowed domains, * for wildcard. Example: %s', ['nextcloud.com;*.example.com']));?></em> <em><?php p($l->t('Enter a semicolon-separated list of allowed domains, * for wildcard. Example: %s', ['nextcloud.com;*.example.com']));?></em>
<p>
<input type="checkbox" id="email_is_login" class="checkbox" name="email_is_login" <?php if ($_['email_is_login'] === 'yes') {
echo ' checked';
} ?>>
<label for="email_is_login"><?php p($l->t('Force email as login name')); ?></label>
</p> </p>
<h3><?php p($l->t('Admin approval')); ?></h3> <h3><?php p($l->t('Admin approval')); ?></h3>
<p> <p>
<input type="checkbox" id="admin_approval_required" class="checkbox" name="admin_approval_required" <?php if ($_['approval_required'] === "yes") { <input type="checkbox" id="admin_approval_required" class="checkbox" name="admin_approval_required" <?php if ($_['approval_required'] === 'yes') {
echo " checked"; echo ' checked';
} ?>> } ?>>
<label for="admin_approval_required"><?php p($l->t('Require admin approval')); ?></label> <label for="admin_approval_required"><?php p($l->t('Require admin approval')); ?></label>
</p> </p>