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
This commit is contained in:
@@ -31,6 +31,7 @@ public function mount(): void
|
|||||||
$siteDescription = Setting::get('site_description');
|
$siteDescription = Setting::get('site_description');
|
||||||
$contactEmail = Setting::get('contact_email');
|
$contactEmail = Setting::get('contact_email');
|
||||||
$maintenanceMode = Setting::get('maintenance_mode', false);
|
$maintenanceMode = Setting::get('maintenance_mode', false);
|
||||||
|
$enableRegistration = Setting::get('enable_registration', false);
|
||||||
|
|
||||||
$this->form->fill([
|
$this->form->fill([
|
||||||
'site_name' => is_string($siteName) ? $siteName : config('app.name'),
|
'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 : '',
|
'site_description' => is_string($siteDescription) || is_null($siteDescription) ? $siteDescription : '',
|
||||||
'contact_email' => is_string($contactEmail) || is_null($contactEmail) ? $contactEmail : '',
|
'contact_email' => is_string($contactEmail) || is_null($contactEmail) ? $contactEmail : '',
|
||||||
'maintenance_mode' => is_bool($maintenanceMode) ? $maintenanceMode : false,
|
'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')
|
Forms\Components\Section::make('System')
|
||||||
->schema([
|
->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')
|
Forms\Components\Toggle::make('maintenance_mode')
|
||||||
->label('Maintenance Mode')
|
->label('Maintenance Mode')
|
||||||
->helperText('Enable to put the site in 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('site_description', $data['site_description'] ?? '');
|
||||||
Setting::set('contact_email', $data['contact_email'] ?? '');
|
Setting::set('contact_email', $data['contact_email'] ?? '');
|
||||||
Setting::set('maintenance_mode', $data['maintenance_mode'] ?? false, 'boolean');
|
Setting::set('maintenance_mode', $data['maintenance_mode'] ?? false, 'boolean');
|
||||||
|
Setting::set('enable_registration', $data['enable_registration'] ?? false, 'boolean');
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Settings saved successfully')
|
->title('Settings saved successfully')
|
||||||
|
|||||||
26
src/app/Http/Middleware/CheckRegistrationEnabled.php
Normal file
26
src/app/Http/Middleware/CheckRegistrationEnabled.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class CheckRegistrationEnabled
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
* Block registration routes if registration is disabled in settings.
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next): Response
|
||||||
|
{
|
||||||
|
$registrationEnabled = Setting::get('enable_registration', false);
|
||||||
|
|
||||||
|
if (!$registrationEnabled) {
|
||||||
|
abort(403, 'User registration is currently disabled. Please contact an administrator.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ public function boot(): void
|
|||||||
'secondary_color' => Setting::get('secondary_color', '#8b5cf6'),
|
'secondary_color' => Setting::get('secondary_color', '#8b5cf6'),
|
||||||
'accent_color' => Setting::get('accent_color', '#10b981'),
|
'accent_color' => Setting::get('accent_color', '#10b981'),
|
||||||
'description' => Setting::get('site_description'),
|
'description' => Setting::get('site_description'),
|
||||||
|
'enable_registration' => Setting::get('enable_registration', false),
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$view->with('siteSettings', [
|
$view->with('siteSettings', [
|
||||||
@@ -39,6 +40,7 @@ public function boot(): void
|
|||||||
'secondary_color' => '#8b5cf6',
|
'secondary_color' => '#8b5cf6',
|
||||||
'accent_color' => '#10b981',
|
'accent_color' => '#10b981',
|
||||||
'description' => null,
|
'description' => null,
|
||||||
|
'enable_registration' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
health: '/up',
|
health: '/up',
|
||||||
)
|
)
|
||||||
->withMiddleware(function (Middleware $middleware) {
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
//
|
$middleware->alias([
|
||||||
|
'registration.enabled' => \App\Http\Middleware\CheckRegistrationEnabled::class,
|
||||||
|
]);
|
||||||
})
|
})
|
||||||
->withExceptions(function (Exceptions $exceptions) {
|
->withExceptions(function (Exceptions $exceptions) {
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -12,10 +12,12 @@
|
|||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::middleware('guest')->group(function () {
|
Route::middleware('guest')->group(function () {
|
||||||
Route::get('register', [RegisteredUserController::class, 'create'])
|
Route::middleware('registration.enabled')->group(function () {
|
||||||
->name('register');
|
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'])
|
Route::get('login', [AuthenticatedSessionController::class, 'create'])
|
||||||
->name('login');
|
->name('login');
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome');
|
return redirect()->route('login');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/dashboard', function () {
|
Route::get('/dashboard', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user