Make mail confirmation optional

Signed-off-by: nienzu <ibqqz0602@gmail.com>
This commit is contained in:
nienzu 2020-10-13 12:06:54 +08:00
parent ab61503ef3
commit bdb40a2d11
6 changed files with 45 additions and 13 deletions

View File

@ -99,6 +99,7 @@ class RegisterController extends Controller {
$params = [ $params = [
'email' => $email, 'email' => $email,
'message' => $message ?: $emailHint, 'message' => $message ?: $emailHint,
'disable_email_verification' => $this->config->getAppValue($this->appName, 'disable_email_verification', 'no')
]; ];
return new TemplateResponse('registration', 'form/email', $params, 'guest'); return new TemplateResponse('registration', 'form/email', $params, 'guest');
} }
@ -126,6 +127,17 @@ class RegisterController extends Controller {
$registration = $this->registrationService->createRegistration($email); $registration = $this->registrationService->createRegistration($email);
} }
if ($this->config->getAppValue($this->appName, 'disable_email_verification', 'no') === 'yes') {
return new RedirectResponse(
$this->urlGenerator->linkToRoute(
'registration.register.showUserForm',
[
'secret' => $registration->getClientSecret(),
'token' => $registration->getToken()
]
)
);
} else {
try { try {
$this->mailService->sendTokenByMail($registration); $this->mailService->sendTokenByMail($registration);
} catch (RegistrationException $e) { } catch (RegistrationException $e) {
@ -139,6 +151,7 @@ class RegisterController extends Controller {
) )
); );
} }
}
/** /**
* @NoCSRFRequired * @NoCSRFRequired

View File

@ -55,7 +55,8 @@ class SettingsController extends Controller {
?bool $admin_approval_required, ?bool $admin_approval_required,
?bool $email_is_login, ?bool $email_is_login,
?bool $domains_is_blocklist, ?bool $domains_is_blocklist,
?bool $show_domains) { ?bool $show_domains,
?bool $disable_email_verification) {
// 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');
@ -67,6 +68,7 @@ class SettingsController extends Controller {
$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, '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');
// handle groups // handle groups
$groups = $this->groupmanager->search(''); $groups = $this->groupmanager->search('');

View File

@ -63,6 +63,7 @@ class RegistrationSettings implements ISettings {
$emailIsLogin = $this->config->getAppValue($this->appName, 'email_is_login', 'no'); $emailIsLogin = $this->config->getAppValue($this->appName, 'email_is_login', 'no');
$domainsIsBlocklist = $this->config->getAppValue($this->appName, 'domains_is_blocklist', 'no'); $domainsIsBlocklist = $this->config->getAppValue($this->appName, 'domains_is_blocklist', 'no');
$showDomains = $this->config->getAppValue($this->appName, 'show_domains', 'no'); $showDomains = $this->config->getAppValue($this->appName, 'show_domains', 'no');
$disableEmailVerification = $this->config->getAppValue($this->appName, 'disable_email_verification', 'no');
return new TemplateResponse('registration', 'admin', [ return new TemplateResponse('registration', 'admin', [
'groups' => $groupIds, 'groups' => $groupIds,
@ -72,6 +73,7 @@ class RegistrationSettings implements ISettings {
'email_is_login' => $emailIsLogin, 'email_is_login' => $emailIsLogin,
'domains_is_blocklist' => $domainsIsBlocklist, 'domains_is_blocklist' => $domainsIsBlocklist,
'show_domains' => $showDomains, 'show_domains' => $showDomains,
'disable_email_verification' => $disableEmailVerification,
], ''); ], '');
} }

View File

@ -22,6 +22,14 @@ foreach ($_['groups'] as $group) {
</label> </label>
</p> </p>
<h3><?php p($l->t('Disable Email Verification')); ?></h3>
<p>
<input type="checkbox" id="disable_email_verification" class="checkbox" name="disable_email_verification" <?php if ($_['disable_email_verification'] === 'yes') {
echo ' checked';
} ?>>
<label for="disable_email_verification"><?php p($l->t('Let user can register directly without email verification')); ?></label>
</p>
<h3><?php p($l->t('Allowed email domains')); ?></h3> <h3><?php p($l->t('Allowed email domains')); ?></h3>
<p> <p>
<label> <label>

View File

@ -17,7 +17,12 @@ style('registration', 'style');
<img id="email-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/mail.svg')); ?>" alt=""/> <img id="email-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/mail.svg')); ?>" alt=""/>
</p> </p>
<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" /> <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>" />
<input type="submit" id="submit" value="<?php p($l->t('Request verification link')); ?>" /> <input type="submit" id="submit" value="<?php
if ($_['disable_email_verification'] === 'yes') {
echo p($l->t('Start register process'));
} else {
echo p($l->t('Request verification link'));
}?>" />
<a id="lost-password-back" href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('core.login.showLoginForm')) ?>"> <a id="lost-password-back" href="<?php print_unescaped(\OC::$server->getURLGenerator()->linkToRoute('core.login.showLoginForm')) ?>">
<?php p($l->t('Back to login')); ?> <?php p($l->t('Back to login')); ?>

View File

@ -125,6 +125,7 @@ class RegisterControllerTest extends TestCase {
public function testShowEmailForm(string $email, string $message): void { public function testShowEmailForm(string $email, string $message): void {
$controller = $this->getController(); $controller = $this->getController();
$response = $controller->showEmailForm($email, $message); $response = $controller->showEmailForm($email, $message);
$disable_email_verification = $this->config->getAppValue("registration", 'disable_email_verification', 'no');
self::assertSame(TemplateResponse::RENDER_AS_GUEST, $response->getRenderAs()); self::assertSame(TemplateResponse::RENDER_AS_GUEST, $response->getRenderAs());
self::assertSame('form/email', $response->getTemplateName()); self::assertSame('form/email', $response->getTemplateName());
@ -132,6 +133,7 @@ class RegisterControllerTest extends TestCase {
self::assertSame([ self::assertSame([
'email' => $email, 'email' => $email,
'message' => $message, 'message' => $message,
'disable_email_verification' => $disable_email_verification,
], $response->getParams()); ], $response->getParams());
} }