diff --git a/app/Http/Middleware/ActivePublicModule.php b/app/Http/Middleware/ActivePublicModule.php new file mode 100644 index 00000000..4a94c640 --- /dev/null +++ b/app/Http/Middleware/ActivePublicModule.php @@ -0,0 +1,28 @@ +first()->active) { + return redirect()->route('app.index'); + } + if ($module && ! Module::where('key', $module)->first()->expose_public) { + return redirect()->route('app.index'); + } + + return $next($request); + } +} diff --git a/database/migrations/2024_10_07_055750_add_expose_public_to_modules_table.php b/database/migrations/2024_10_07_055750_add_expose_public_to_modules_table.php new file mode 100644 index 00000000..bf311f87 --- /dev/null +++ b/database/migrations/2024_10_07_055750_add_expose_public_to_modules_table.php @@ -0,0 +1,28 @@ +boolean('expose_public')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('modules', function (Blueprint $table) { + $table->dropColumn(['expose_public']); + }); + } +}; diff --git a/database/seeders/ModuleDemoSeeder.php b/database/seeders/ModuleDemoSeeder.php index 31ee8162..0ddda28f 100644 --- a/database/seeders/ModuleDemoSeeder.php +++ b/database/seeders/ModuleDemoSeeder.php @@ -16,18 +16,22 @@ public function run(): void [ 'key' => 'registration', 'active' => true, + 'expose_public' => false, ], [ 'key' => 'randomGenerator', 'active' => true, + 'expose_public' => false, ], [ 'key' => 'scoreSystem', 'active' => true, + 'expose_public' => false, ], [ 'key' => 'countdown', 'active' => true, + 'expose_public' => false, ], ]; @@ -40,6 +44,7 @@ public function run(): void // update module $existingModule->active = $module['active']; + $existingModule->expose_public = $module['expose_public']; // save module $existingModule->save(); diff --git a/database/seeders/ModuleErstiwocheSeeder.php b/database/seeders/ModuleErstiwocheSeeder.php index 1dbaa08f..7518b1fd 100644 --- a/database/seeders/ModuleErstiwocheSeeder.php +++ b/database/seeders/ModuleErstiwocheSeeder.php @@ -16,6 +16,7 @@ public function run(): void [ 'key' => 'registration', 'active' => true, + 'expose_public' => false, ], ]; @@ -23,11 +24,12 @@ public function run(): void // check if module with key already exists $existingModule = Module::where('key', $module['key'])->first(); if (! $existingModule) { - throw new \Exception('Module with key "'.$module['key'].'" not found.'); + throw new \Exception('Module with key "' . $module['key'] . '" not found.'); } // update module $existingModule->active = $module['active']; + $existingModule->expose_public = $module['expose_public']; // save module $existingModule->save(); diff --git a/database/seeders/ModuleGerolsteinSeeder.php b/database/seeders/ModuleGerolsteinSeeder.php index f1facd7a..843fecac 100644 --- a/database/seeders/ModuleGerolsteinSeeder.php +++ b/database/seeders/ModuleGerolsteinSeeder.php @@ -16,14 +16,17 @@ public function run(): void [ 'key' => 'randomGenerator', 'active' => true, + 'expose_public' => true, ], [ 'key' => 'scoreSystem', 'active' => true, + 'expose_public' => true, ], [ 'key' => 'countdown', 'active' => true, + 'expose_public' => true, ], ]; @@ -36,6 +39,7 @@ public function run(): void // update module $existingModule->active = $module['active']; + $existingModule->expose_public = $module['expose_public']; // save module $existingModule->save(); diff --git a/database/seeders/ModuleSeeder.php b/database/seeders/ModuleSeeder.php index 916560d9..2f786a40 100644 --- a/database/seeders/ModuleSeeder.php +++ b/database/seeders/ModuleSeeder.php @@ -16,18 +16,22 @@ public function run(): void [ 'key' => 'registration', 'active' => false, + 'expose_public' => false, ], [ 'key' => 'randomGenerator', 'active' => false, + 'expose_public' => false, ], [ 'key' => 'scoreSystem', 'active' => false, + 'expose_public' => false, ], [ 'key' => 'countdown', 'active' => false, + 'expose_public' => false, ], ]; @@ -42,6 +46,7 @@ public function run(): void $newModule = new Module; $newModule->key = $module['key']; $newModule->active = $module['active']; + $newModule->expose_public = $module['expose_public']; // save module $newModule->save(); diff --git a/routes/web.php b/routes/web.php index 3490bc79..ee5687f0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,6 +10,7 @@ use App\Http\Controllers\DashboardEventController; use App\Http\Controllers\DashboardTutorController; use App\Http\Middleware\ActiveModule; +use App\Http\Middleware\ActivePublicModule; use App\Http\Middleware\IsLoggedInTutor; use App\Http\Middleware\RedirectIfTutor; use Illuminate\Auth\Middleware\Authenticate; @@ -107,6 +108,20 @@ Route::get('{slug?}', [DashboardController::class, 'cmsPage'])->where('slug', '.*'); }); +//public routes without authentication +Route::prefix('public')->group(function () { + Route::middleware(ActivePublicModule::class . ':randomGenerator')->group(function () { + Route::get('/random-generator', [DashboardAdminRandomGeneratorController::class, 'display'])->name('dashboard.admin.randomGenerator.display'); + }); + + Route::middleware(ActivePublicModule::class . ':scoreSystem')->group(function () { + Route::get('/score-system', [DashboardAdminScoreSystemController::class, 'display'])->name('dashboard.admin.scoreSystem.display'); + }); + + Route::middleware(ActivePublicModule::class . ':countdown')->group(function () { + Route::get('/countdown', [DashboardAdminCountdownController::class, 'display'])->name('dashboard.admin.countdown.display'); + }); +}); // api routes with authentication Route::prefix('api')->middleware(Authenticate::class)->group(function () { Route::middleware(IsLoggedInTutor::class)->group(function () {