Option for disabling new registered users

This commit is contained in:
Neraste 2017-10-21 14:02:38 +02:00
parent 8c6da61f46
commit 651439c233
4 changed files with 45 additions and 10 deletions

View File

@ -47,14 +47,21 @@ class SettingsController extends Controller {
*
* @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 bool $admin_approval_required newly registered users have to be validated by an admin
* @return DataResponse
*/
public function admin($registered_user_group, $allowed_domains) {
public function admin($registered_user_group, $allowed_domains, $admin_approval_required) {
// handle domains
if ( ( $allowed_domains==='' ) || ( $allowed_domains === NULL ) ){
$this->config->deleteAppValue($this->appName, 'allowed_domains');
}else{
$this->config->setAppValue($this->appName, 'allowed_domains', $allowed_domains);
}
// handle admin validation
$this->config->setAppValue($this->appName, 'admin_approval_required', $admin_approval_required ? "yes" : "no");
// handle groups
$groups = $this->groupmanager->search('');
$group_id_list = array();
foreach ( $groups as $group ) {
@ -92,17 +99,25 @@ class SettingsController extends Controller {
* @return TemplateResponse
*/
public function displayPanel() {
// handle groups
$groups = $this->groupmanager->search('');
$group_id_list = [];
foreach ( $groups as $group ) {
$group_id_list[] = $group->getGid();
}
$current_value = $this->config->getAppValue($this->appName, 'registered_user_group', 'none');
// handle domains
$allowed_domains = $this->config->getAppValue($this->appName, 'allowed_domains', '');
// handle admin validation
$admin_approval_required = $this->config->getAppValue($this->appName, 'admin_approval_required', "no");
return new TemplateResponse('registration', 'admin', [
'groups' => $group_id_list,
'current' => $current_value,
'allowed' => $allowed_domains
'allowed' => $allowed_domains,
'approval_required' => $admin_approval_required
], '');
}
}

View File

@ -106,8 +106,9 @@ class MailService {
/**
* @param string $userId
* @param bool $userIsEnabled
*/
public function notifyAdmins($userId) {
public function notifyAdmins($userId, $userIsEnabled) {
// Notify admin
$admin_users = $this->groupManager->get('admin')->getUsers();
$to_arr = array();
@ -118,7 +119,7 @@ class MailService {
}
}
try {
$this->sendNewUserNotifEmail($to_arr, $userId);
$this->sendNewUserNotifEmail($to_arr, $userId, $userIsEnabled);
} catch (\Exception $e) {
$this->logger->error('Sending admin notification email failed: '. $e->getMessage());
}
@ -128,16 +129,27 @@ class MailService {
* Sends new user notification email to admin
* @param array $to
* @param string $username the new user
* @param bool $userIsEnabled the new user account is enabled
* @throws \Exception
*/
private function sendNewUserNotifEmail(array $to, $username) {
private function sendNewUserNotifEmail(array $to, $username, $userIsEnabled) {
$template_var = [
'user' => $username,
'sitename' => $this->defaults->getName()
];
$html_template = new TemplateResponse('registration', 'email.newuser.disabled_html', $template_var, 'blank');
// handle user enableness
if ($userIsEnabled) {
$html_template_file = 'email.newuser_html';
$plaintext_template_file = 'email.newuser_plaintext';
} else {
$html_template_file = 'email.newuser.disabled_html';
$plaintext_template_file = 'email.newuser.disabled_plaintext';
}
$html_template = new TemplateResponse('registration', $html_template_file, $template_var, 'blank');
$html_part = $html_template->render();
$plaintext_template = new TemplateResponse('registration', 'email.newuser.disabled_plaintext', $template_var, 'blank');
$plaintext_template = new TemplateResponse('registration', $plaintext_template_file, $template_var, 'blank');
$plaintext_part = $plaintext_template->render();
$subject = $this->l10n->t('A new user "%s" has created an account on %s', [$username, $this->defaults->getName()]);

View File

@ -293,8 +293,11 @@ class RegistrationService {
}
}
// Disable user unconditionaly
$user->setEnabled(false);
// disable user if this is requested by config
$admin_approval_required = $this->config->getAppValue($this->appName, 'admin_approval_required', "no");
if ($admin_approval_required) {
$user->setEnabled(false);
}
// Delete pending registration if no client secret is stored
if($registration->getClientSecret() === null) {
@ -304,7 +307,7 @@ class RegistrationService {
}
}
$this->mailService->notifyAdmins($userId);
$this->mailService->notifyAdmins($userId, $user->isEnabled());
return $user;
}

View File

@ -23,4 +23,9 @@ foreach ( $_['groups'] as $group ) {
<em><?php p($l->t('Enter a semicolon-separated list of allowed domains. Example: owncloud.com;github.com'));?></em>
</p>
<p>
<label for="admin_approval_required"><?php p($l->t('Require admin approval?')); ?>
<input type="checkbox" id="admin_approval_required" name="admin_approval_required" <?php if($_['approval_required'] == "yes" ) echo " checked"; ?>>
</label>
</p>
</form>