diff --git a/misuzu.php b/misuzu.php index a11fe6bf..2851bf3e 100644 --- a/misuzu.php +++ b/misuzu.php @@ -267,7 +267,9 @@ MIG; tpl_add_path(__DIR__ . '/templates'); - if ($app->underLockdown()) { + $misuzuBypassLockdown = !empty($misuzuBypassLockdown); + + if (!$misuzuBypassLockdown && $app->underLockdown()) { http_response_code(503); echo tpl_render('auth.lockdown'); exit; @@ -294,6 +296,12 @@ MIG; } } + if (!$misuzuBypassLockdown && $app->isStagingSite() && !$app->hasActiveSession()) { + http_response_code(401); + echo tpl_render('auth.private'); + exit; + } + $inManageMode = starts_with($_SERVER['REQUEST_URI'], '/manage'); $hasManageAccess = perms_check(perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId()), MSZ_PERM_GENERAL_CAN_MANAGE); tpl_var('has_manage_access', $hasManageAccess); diff --git a/public/auth.php b/public/auth.php index eae17e5c..0b874be5 100644 --- a/public/auth.php +++ b/public/auth.php @@ -3,6 +3,10 @@ use Carbon\Carbon; use Misuzu\Application; use Misuzu\Database; +$isSubmission = !empty($_POST['auth']) && is_array($_POST['auth']); +$authMode = $isSubmission ? ($_POST['auth']['mode'] ?? '') : ($_GET['m'] ?? 'login'); +$misuzuBypassLockdown = $authMode === 'login' || $authMode === 'get_user'; + require_once __DIR__ . '/../misuzu.php'; $usernameValidationErrors = [ @@ -14,9 +18,8 @@ $usernameValidationErrors = [ ]; $preventRegistration = $app->disableRegistration(); +$isStagingSite = $app->isStagingSite(); -$isSubmission = !empty($_POST['auth']) && is_array($_POST['auth']); -$authMode = $isSubmission ? ($_POST['auth']['mode'] ?? '') : ($_GET['m'] ?? 'login'); $authUsername = $isSubmission ? ($_POST['auth']['username'] ?? '') : ($_GET['username'] ?? ''); $authEmail = $isSubmission ? ($_POST['auth']['email'] ?? '') : ($_GET['email'] ?? ''); $authPassword = $_POST['auth']['password'] ?? ''; @@ -24,6 +27,7 @@ $authVerification = $_POST['auth']['verification'] ?? ''; tpl_vars([ 'prevent_registration' => $preventRegistration, + 'is_staging_site' => $isStagingSite, 'auth_mode' => $authMode, 'auth_username' => $authUsername, 'auth_email' => $authEmail, @@ -57,6 +61,11 @@ switch ($authMode) { break; } + if ($isStagingSite) { + header('Location: /'); + return; + } + $resetUser = (int)($_POST['user'] ?? $_GET['u'] ?? 0); $getResetUser = Database::prepare(' SELECT `user_id`, `username` @@ -144,7 +153,7 @@ switch ($authMode) { break; case 'forgot': - if ($app->hasActiveSession()) { + if ($app->hasActiveSession() || $isStagingSite) { header('Location: /'); break; } diff --git a/public/profile.php b/public/profile.php index 94760b34..543cb0df 100644 --- a/public/profile.php +++ b/public/profile.php @@ -1,10 +1,12 @@ underLockdown() || boolval($this->config['Auth']['prevent_registration'] ?? false); + return $this->underLockdown() + || $this->isStagingSite() + || boolval($this->config['Auth']['prevent_registration'] ?? false); + } + + public function isStagingSite(): bool + { + return boolval($this->config['Auth']['staging'] ?? false); } public function getLinkedData(): array diff --git a/templates/auth/auth.twig b/templates/auth/auth.twig index 0ef7b09b..cfedbe53 100644 --- a/templates/auth/auth.twig +++ b/templates/auth/auth.twig @@ -1,126 +1,63 @@ {% extends 'auth/master.twig' %} +{% from 'auth/macros.twig' import auth_login %} {% block content %} -