From cf6079d58cb6c7ec9f29c681c9e0876353b0ee2c Mon Sep 17 00:00:00 2001 From: theRADcozaDEV Date: Wed, 11 Mar 2026 07:43:25 +0200 Subject: [PATCH] Redirect landing to login, add registration toggle Changes: - Landing page (/) now redirects to /login - Added 'Enable User Registration' setting (off by default) - Created CheckRegistrationEnabled middleware - Registration routes blocked when setting is disabled - Admin can toggle registration in Settings > System --- src/app/Filament/Pages/Settings.php | 7 +++++ .../Middleware/CheckRegistrationEnabled.php | 26 +++++++++++++++++++ src/app/Providers/AppServiceProvider.php | 2 ++ src/bootstrap/app.php | 4 ++- src/routes/auth.php | 8 +++--- src/routes/web.php | 2 +- 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/app/Http/Middleware/CheckRegistrationEnabled.php diff --git a/src/app/Filament/Pages/Settings.php b/src/app/Filament/Pages/Settings.php index 4e275a6..0fd8bb6 100644 --- a/src/app/Filament/Pages/Settings.php +++ b/src/app/Filament/Pages/Settings.php @@ -31,6 +31,7 @@ public function mount(): void $siteDescription = Setting::get('site_description'); $contactEmail = Setting::get('contact_email'); $maintenanceMode = Setting::get('maintenance_mode', false); + $enableRegistration = Setting::get('enable_registration', false); $this->form->fill([ 'site_name' => is_string($siteName) ? $siteName : config('app.name'), @@ -41,6 +42,7 @@ public function mount(): void 'site_description' => is_string($siteDescription) || is_null($siteDescription) ? $siteDescription : '', 'contact_email' => is_string($contactEmail) || is_null($contactEmail) ? $contactEmail : '', 'maintenance_mode' => is_bool($maintenanceMode) ? $maintenanceMode : false, + 'enable_registration' => is_bool($enableRegistration) ? $enableRegistration : false, ]); } @@ -87,6 +89,10 @@ public function form(Form $form): Form Forms\Components\Section::make('System') ->schema([ + Forms\Components\Toggle::make('enable_registration') + ->label('Enable User Registration') + ->helperText('Allow new users to register. When disabled, only admins can create users.'), + Forms\Components\Toggle::make('maintenance_mode') ->label('Maintenance Mode') ->helperText('Enable to put the site in maintenance mode'), @@ -116,6 +122,7 @@ public function save(): void Setting::set('site_description', $data['site_description'] ?? ''); Setting::set('contact_email', $data['contact_email'] ?? ''); Setting::set('maintenance_mode', $data['maintenance_mode'] ?? false, 'boolean'); + Setting::set('enable_registration', $data['enable_registration'] ?? false, 'boolean'); Notification::make() ->title('Settings saved successfully') diff --git a/src/app/Http/Middleware/CheckRegistrationEnabled.php b/src/app/Http/Middleware/CheckRegistrationEnabled.php new file mode 100644 index 0000000..b129b8f --- /dev/null +++ b/src/app/Http/Middleware/CheckRegistrationEnabled.php @@ -0,0 +1,26 @@ + Setting::get('secondary_color', '#8b5cf6'), 'accent_color' => Setting::get('accent_color', '#10b981'), 'description' => Setting::get('site_description'), + 'enable_registration' => Setting::get('enable_registration', false), ]); } catch (\Exception $e) { $view->with('siteSettings', [ @@ -39,6 +40,7 @@ public function boot(): void 'secondary_color' => '#8b5cf6', 'accent_color' => '#10b981', 'description' => null, + 'enable_registration' => false, ]); } }); diff --git a/src/bootstrap/app.php b/src/bootstrap/app.php index d654276..ddc2dc6 100644 --- a/src/bootstrap/app.php +++ b/src/bootstrap/app.php @@ -12,7 +12,9 @@ health: '/up', ) ->withMiddleware(function (Middleware $middleware) { - // + $middleware->alias([ + 'registration.enabled' => \App\Http\Middleware\CheckRegistrationEnabled::class, + ]); }) ->withExceptions(function (Exceptions $exceptions) { // diff --git a/src/routes/auth.php b/src/routes/auth.php index 3926ecf..075dde0 100644 --- a/src/routes/auth.php +++ b/src/routes/auth.php @@ -12,10 +12,12 @@ use Illuminate\Support\Facades\Route; Route::middleware('guest')->group(function () { - Route::get('register', [RegisteredUserController::class, 'create']) - ->name('register'); + Route::middleware('registration.enabled')->group(function () { + Route::get('register', [RegisteredUserController::class, 'create']) + ->name('register'); - Route::post('register', [RegisteredUserController::class, 'store']); + Route::post('register', [RegisteredUserController::class, 'store']); + }); Route::get('login', [AuthenticatedSessionController::class, 'create']) ->name('login'); diff --git a/src/routes/web.php b/src/routes/web.php index 74bb7ca..376d12e 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Route; Route::get('/', function () { - return view('welcome'); + return redirect()->route('login'); }); Route::get('/dashboard', function () {