From 3ef5f24d05ad6b5e98056ee4b7f06137b28dd68c Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Wed, 29 May 2024 17:18:10 +0200 Subject: [PATCH] fix: user registration when it's disabled --- src/classes/wishthis/Page.php | 27 ++++++++++++++++----------- src/pages/register.php | 29 +++++++---------------------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/classes/wishthis/Page.php b/src/classes/wishthis/Page.php index 43e89409..bfe9feba 100644 --- a/src/classes/wishthis/Page.php +++ b/src/classes/wishthis/Page.php @@ -507,7 +507,7 @@ class Page 'icon' => 'sign out alternate', ]; } else { - $pages[$login] = [ + $pages[$login] = [ 'text' => __('Login'), 'alignment' => 'right', 'items' => [ @@ -518,17 +518,22 @@ class Page ], ], ]; - $pages[$register] = [ - 'text' => __('Register'), - 'alignment' => 'right', - 'items' => [ - [ - 'text' => __('Register'), - 'url' => Page::PAGE_REGISTER, - 'icon' => 'user plus alternate', + + $registrationDisabled = defined('DISABLE_USER_REGISTRATION') && true === DISABLE_USER_REGISTRATION; + + if (!$registrationDisabled) { + $pages[$register] = [ + 'text' => __('Register'), + 'alignment' => 'right', + 'items' => [ + [ + 'text' => __('Register'), + 'url' => Page::PAGE_REGISTER, + 'icon' => 'user plus alternate', + ], ], - ], - ]; + ]; + } } if (100 === $user->getPower()) { diff --git a/src/pages/register.php b/src/pages/register.php index 904daa8c..8d1936cb 100644 --- a/src/pages/register.php +++ b/src/pages/register.php @@ -8,14 +8,15 @@ 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'); $buttonSubmit = $passwordReset ? __('Reset') : __('Register'); $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 ->query( 'SELECT * @@ -115,14 +116,6 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { $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 */ @@ -221,17 +214,11 @@ $page->navigation(); messages() ?> - +
-

- -

+

The owner of this instance has disabled user registration.

- +
@@ -321,9 +308,7 @@ $page->navigation(); ?>

- +