Skip to content

Commit

Permalink
Make mail confirmation optional
Browse files Browse the repository at this point in the history
Signed-off-by: nienzu <ibqqz0602@gmail.com>
  • Loading branch information
Nienzu committed Oct 20, 2020
1 parent ab61503 commit 78e02b9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
35 changes: 24 additions & 11 deletions lib/Controller/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function showEmailForm(string $email = '', string $message = ''): Templat
$params = [
'email' => $email,
'message' => $message ?: $emailHint,
'disable_email_verification' => $this->config->getAppValue($this->appName, 'disable_email_verification', 'no')
];
return new TemplateResponse('registration', 'form/email', $params, 'guest');
}
Expand Down Expand Up @@ -126,18 +127,30 @@ public function submitEmailForm(string $email): Response {
$registration = $this->registrationService->createRegistration($email);
}

try {
$this->mailService->sendTokenByMail($registration);
} catch (RegistrationException $e) {
return $this->showEmailForm($email, $e->getMessage());
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 {
$this->mailService->sendTokenByMail($registration);
} catch (RegistrationException $e) {
return $this->showEmailForm($email, $e->getMessage());
}

return new RedirectResponse(
$this->urlGenerator->linkToRoute(
'registration.register.showVerificationForm',
['secret' => $registration->getClientSecret()]
)
);
}

return new RedirectResponse(
$this->urlGenerator->linkToRoute(
'registration.register.showVerificationForm',
['secret' => $registration->getClientSecret()]
)
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function admin(string $registered_user_group,
?bool $admin_approval_required,
?bool $email_is_login,
?bool $domains_is_blocklist,
?bool $show_domains) {
?bool $show_domains,
?bool $disable_email_verification) {
// handle domains
if (($allowed_domains === '') || ($allowed_domains === null)) {
$this->config->deleteAppValue($this->appName, 'allowed_domains');
Expand All @@ -67,6 +68,7 @@ public function admin(string $registered_user_group,
$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, 'show_domains', $show_domains ? 'yes' : 'no');
$this->config->setAppValue($this->appName, 'disable_email_verification', $disable_email_verification ? 'yes' : 'no');

// handle groups
$groups = $this->groupmanager->search('');
Expand Down
2 changes: 2 additions & 0 deletions lib/Settings/RegistrationSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getForm(): TemplateResponse {
$emailIsLogin = $this->config->getAppValue($this->appName, 'email_is_login', 'no');
$domainsIsBlocklist = $this->config->getAppValue($this->appName, 'domains_is_blocklist', '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', [
'groups' => $groupIds,
Expand All @@ -72,6 +73,7 @@ public function getForm(): TemplateResponse {
'email_is_login' => $emailIsLogin,
'domains_is_blocklist' => $domainsIsBlocklist,
'show_domains' => $showDomains,
'disable_email_verification' => $disableEmailVerification,
], '');
}

Expand Down
8 changes: 8 additions & 0 deletions templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
</label>
</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>
<p>
<label>
Expand Down
7 changes: 6 additions & 1 deletion templates/form/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
<img id="email-icon" class="svg" src="<?php print_unescaped(image_path('', 'actions/mail.svg')); ?>" alt=""/>
</p>
<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')) ?>">
<?php p($l->t('Back to login')); ?>
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Controller/RegisterControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ public function dataShowEmailForm(): array {
public function testShowEmailForm(string $email, string $message): void {
$controller = $this->getController();
$response = $controller->showEmailForm($email, $message);
$disable_email_verification = $this->config->getAppValue($controller->appName, 'disable_email_verification', 'no');

self::assertSame(TemplateResponse::RENDER_AS_GUEST, $response->getRenderAs());
self::assertSame('form/email', $response->getTemplateName());

self::assertSame([
'email' => $email,
'message' => $message,
'disable_email_verification' => $disable_email_verification,
], $response->getParams());
}

Expand Down

0 comments on commit 78e02b9

Please sign in to comment.