pixelfed/app/Http/Middleware/EnsureCuratedRegistration.php
Charlie McMackin 4248abde7c Extract and add EnsureCuratedRegistration middleware
Previously the various config checks for curated registration were preventing
`artisan route:list` from running successfully.

Here we extract that logic from the controller's contructor and place in a
middleware around the CuratedRegisterController routes.
2024-09-07 18:33:33 -05:00

28 lines
825 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class EnsureCuratedRegistration
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
abort_unless((bool) config_cache('instance.curated_registration.enabled'), 404);
if ((bool) config_cache('pixelfed.open_registration')) {
abort_if(config('instance.curated_registration.state.only_enabled_on_closed_reg'), 404);
} else {
abort_unless(config('instance.curated_registration.state.fallback_on_closed_reg'), 404);
}
return $next($request);
}
}