Select Git revision
CheckPrivateModeMiddleware.php

Sofiane Lasri authored
- Changed the retrieval of the website name in the sidebar component to use the `DbConfig` model for dynamic configuration. - Updated the `set` method in the `DbConfig` model to allow null values for configuration. - Refactored the public layout to use the website name from `DbConfig` instead of a hardcoded value. - Adjusted the default value for maintenance mode and website name in the settings view to match the new configuration method. - Modified the middleware to check the maintenance mode from the `DbConfig` model. - Updated the `SettingsController` to use `has` instead of `filled` for checking request inputs related to maintenance mode and website name.
CheckPrivateModeMiddleware.php 935 B
<?php
namespace App\Http\Middleware;
use App\Models\DbConfig;
use Closure;
use Illuminate\Http\Request;
class CheckPrivateModeMiddleware
{
public function handle(Request $request, Closure $next)
{
$privateModeEnabled = DbConfig::get('maintenance_mode', 'true');
$privateModeSecret = config('app.private_mode_secret');
$userSecretInput = $request->input('secret');
$secretIsUsable = ! empty($privateModeSecret) && $privateModeSecret === $userSecretInput;
if ($privateModeEnabled) {
if (! $secretIsUsable && ! auth()->check()) {
if (! $request->is('maintenance')) {
return redirect()->route('maintenance');
}
}
}
if (! $privateModeEnabled && $request->is('maintenance') && ! auth()->check()) {
return redirect()->route('index');
}
return $next($request);
}
}