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 13, 2020
1 parent ab61503 commit 07bc320
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
['name' => 'settings#admin', 'url' => '/settings', 'verb' => 'POST'],
['name' => 'register#showEmailForm', 'url' => '/', 'verb' => 'GET'],
['name' => 'register#submitEmailForm', 'url' => '/', 'verb' => 'POST'],
['name' => 'register#submitEmailFormWithoutVerify', 'url' => '/direct', 'verb' => 'POST'],
['name' => 'register#showVerificationForm', 'url' => '/verify/{secret}', 'verb' => 'GET'],
['name' => 'register#submitVerificationForm', 'url' => '/verify/{secret}', 'verb' => 'POST'],
['name' => 'register#showUserForm', 'url' => '/register/{secret}/{token}', 'verb' => 'GET'],
Expand Down
33 changes: 33 additions & 0 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 @@ -140,6 +141,38 @@ public function submitEmailForm(string $email): Response {
);
}

/**
* @PublicPage
* @AnonRateThrottle(limit=5, period=300)
*
* @param string $email
* @return TemplateResponse
*/
public function submitEmailFormWithoutVerify(string $email): Response {
try {
// Registration already in progress, update token and continue with verification
$registration = $this->registrationService->getRegistrationForEmail($email);
$this->registrationService->generateNewToken($registration);
} catch (DoesNotExistException $e) {
// No registration in progress
try {
$this->registrationService->validateEmail($email);
} catch (RegistrationException $e) {
return $this->showEmailForm($email, $e->getMessage());
}

$registration = $this->registrationService->createRegistration($email);
}


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

/**
* @NoCSRFRequired
* @PublicPage
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
13 changes: 11 additions & 2 deletions templates/form/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
/** @var \OCP\IL10N $l */
style('registration', 'style');
?>
<form action="" method="post">
<form action="<?php if ($_['disable_email_verification'] === 'yes') {
echo 'direct';
} else {
echo '';
} ?>" method="post">
<fieldset>
<?php if ($_['message']): ?>
<ul class="error">
Expand All @@ -17,7 +21,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

0 comments on commit 07bc320

Please sign in to comment.