fix: user registration when it's disabled

This commit is contained in:
Jay Trees 2024-05-29 17:18:10 +02:00
parent f37ac929cc
commit 3ef5f24d05
2 changed files with 23 additions and 33 deletions

View file

@ -507,7 +507,7 @@ class Page
'icon' => 'sign out alternate', 'icon' => 'sign out alternate',
]; ];
} else { } else {
$pages[$login] = [ $pages[$login] = [
'text' => __('Login'), 'text' => __('Login'),
'alignment' => 'right', 'alignment' => 'right',
'items' => [ 'items' => [
@ -518,17 +518,22 @@ class Page
], ],
], ],
]; ];
$pages[$register] = [
'text' => __('Register'), $registrationDisabled = defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION;
'alignment' => 'right',
'items' => [ if (!$registrationDisabled) {
[ $pages[$register] = [
'text' => __('Register'), 'text' => __('Register'),
'url' => Page::PAGE_REGISTER, 'alignment' => 'right',
'icon' => 'user plus alternate', 'items' => [
[
'text' => __('Register'),
'url' => Page::PAGE_REGISTER,
'icon' => 'user plus alternate',
],
], ],
], ];
]; }
} }
if (100 === $user->getPower()) { if (100 === $user->getPower()) {

View file

@ -8,14 +8,15 @@
namespace wishthis; namespace wishthis;
$passwordReset = isset($_GET['password-reset'], $_GET['token']); $passwordReset = isset($_GET['password-reset'], $_GET['token']);
$registrationDisabled = defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION;
$pageTitle = $passwordReset ? __('Reset password') : __('Register'); $pageTitle = $passwordReset ? __('Reset password') : __('Register');
$buttonSubmit = $passwordReset ? __('Reset') : __('Register'); $buttonSubmit = $passwordReset ? __('Reset') : __('Register');
$page = new Page(__FILE__, $pageTitle); $page = new Page(__FILE__, $pageTitle);
if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet']) && !$registrationDisabled) {
$users = $database $users = $database
->query( ->query(
'SELECT * 'SELECT *
@ -115,14 +116,6 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
$locale_user = $locale_browser; $locale_user = $locale_browser;
} }
if (defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION) {
\http_response_code(403);
die(__('The owner of this site has disabled user registrations.'));
return;
}
/** /**
* Register * Register
*/ */
@ -221,17 +214,11 @@ $page->navigation();
<?= $page->messages() ?> <?= $page->messages() ?>
<?php <?php if ($registrationDisabled) { ?>
if (defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION) {
?>
<div class="ui segment"> <div class="ui segment">
<h2 class="ui header"><?= __('Registration disabled') ?></h2> <p>The owner of this instance has disabled user registration.</p>
<p><?= __('The owner of this site has disabled user registrations.') ?></p>
</div> </div>
<?php <?php } else { ?>
} else {
?>
<div class="ui segment"> <div class="ui segment">
<form class="ui form" method="POST"> <form class="ui form" method="POST">
<div class="ui divided relaxed stackable two column grid"> <div class="ui divided relaxed stackable two column grid">
@ -321,9 +308,7 @@ $page->navigation();
?> ?>
</p> </p>
</div> </div>
<?php <?php } ?>
}
?>
</div> </div>
</main> </main>