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.
This commit is contained in:
Charlie McMackin 2024-09-07 09:01:50 -05:00
parent 6615408023
commit 4248abde7c
3 changed files with 46 additions and 22 deletions

View file

@ -17,17 +17,6 @@ use App\Jobs\CuratedOnboarding\CuratedOnboardingNotifyAdminNewApplicationPipelin
class CuratedRegisterController extends Controller
{
public function __construct()
{
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);
}
}
public function index(Request $request)
{
abort_if($request->user(), 404);

View file

@ -0,0 +1,28 @@
<?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);
}
}

View file

@ -1,5 +1,8 @@
<?php
use App\Http\Controllers\CuratedRegisterController;
use App\Http\Middleware\EnsureCuratedRegistration;
Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization'])->group(function () {
Route::get('/', 'SiteController@home')->name('timeline.personal');
Route::redirect('/home', '/')->name('home');
@ -31,17 +34,21 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::post('auth/pci/{id}/{code}', 'ParentalControlsController@inviteRegisterStore');
Route::get('auth/sign_up', 'SiteController@curatedOnboarding')->name('auth.curated-onboarding');
Route::post('auth/sign_up', 'CuratedRegisterController@proceed');
Route::get('auth/sign_up/concierge/response-sent', 'CuratedRegisterController@conciergeResponseSent');
Route::get('auth/sign_up/concierge', 'CuratedRegisterController@concierge');
Route::post('auth/sign_up/concierge', 'CuratedRegisterController@conciergeStore');
Route::get('auth/sign_up/concierge/form', 'CuratedRegisterController@conciergeFormShow');
Route::post('auth/sign_up/concierge/form', 'CuratedRegisterController@conciergeFormStore');
Route::get('auth/sign_up/confirm', 'CuratedRegisterController@confirmEmail');
Route::post('auth/sign_up/confirm', 'CuratedRegisterController@confirmEmailHandle');
Route::get('auth/sign_up/confirmed', 'CuratedRegisterController@emailConfirmed');
Route::get('auth/sign_up/resend-confirmation', 'CuratedRegisterController@resendConfirmation');
Route::post('auth/sign_up/resend-confirmation', 'CuratedRegisterController@resendConfirmationProcess');
Route::controller(CuratedRegisterController::class)->group(function () {
Route::post('auth/sign_up', 'proceed');
Route::get('auth/sign_up/concierge/response-sent', 'conciergeResponseSent');
Route::get('auth/sign_up/concierge', 'concierge');
Route::post('auth/sign_up/concierge', 'conciergeStore');
Route::get('auth/sign_up/concierge/form', 'conciergeFormShow');
Route::post('auth/sign_up/concierge/form', 'conciergeFormStore');
Route::get('auth/sign_up/confirm', 'confirmEmail');
Route::post('auth/sign_up/confirm', 'confirmEmailHandle');
Route::get('auth/sign_up/confirmed', 'emailConfirmed');
Route::get('auth/sign_up/resend-confirmation', 'resendConfirmation');
Route::post('auth/sign_up/resend-confirmation', 'resendConfirmationProcess');
})->middleware(EnsureCuratedRegistration::class);
Route::get('auth/forgot/email', 'UserEmailForgotController@index')->name('email.forgot');
Route::post('auth/forgot/email', 'UserEmailForgotController@store')->middleware('throttle:10,900,forgotEmail');