diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 662048a93..6f99fee43 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -2,6 +2,7 @@ namespace App\Actions\Fortify; +use App\Models\InstanceSettings; use App\Models\Team; use App\Models\User; use Illuminate\Support\Facades\DB; @@ -22,6 +23,11 @@ class CreateNewUser implements CreatesNewUsers */ public function create(array $input): User { + $settings = InstanceSettings::find(0); + if (!$settings->is_registration_enabled) { + Log::info('Registration is disabled'); + abort(403); + } Validator::make($input, [ 'name' => ['required', 'string', 'max:255'], 'email' => [ diff --git a/app/Http/Livewire/InstanceSettings.php b/app/Http/Livewire/InstanceSettings.php new file mode 100644 index 000000000..4efa6db6d --- /dev/null +++ b/app/Http/Livewire/InstanceSettings.php @@ -0,0 +1,46 @@ + 'nullable', + 'settings.wildcard_domain' => 'nullable', + 'settings.public_port_min' => 'required', + 'settings.public_port_max' => 'required', + ]; + public function mount() + { + $this->do_not_track = $this->settings->do_not_track; + $this->is_auto_update_enabled = $this->settings->is_auto_update_enabled; + $this->is_registration_enabled = $this->settings->is_registration_enabled; + $this->is_https_forced = $this->settings->is_https_forced; + } + public function instantSave() + { + $this->settings->do_not_track = $this->do_not_track; + $this->settings->is_auto_update_enabled = $this->is_auto_update_enabled; + $this->settings->is_registration_enabled = $this->is_registration_enabled; + $this->settings->is_https_forced = $this->is_https_forced; + $this->settings->save(); + } + public function submit() + { + $this->resetErrorBag(); + if ($this->settings->public_port_min > $this->settings->public_port_max) { + $this->addError('settings.public_port_min', 'The minimum port must be lower than the maximum port.'); + return; + } + $this->settings->save(); + } +} diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php index f2f8ec1d7..b65eb2a00 100644 --- a/app/Providers/FortifyServiceProvider.php +++ b/app/Providers/FortifyServiceProvider.php @@ -6,6 +6,7 @@ use App\Actions\Fortify\CreateNewUser; use App\Actions\Fortify\ResetUserPassword; use App\Actions\Fortify\UpdateUserPassword; use App\Actions\Fortify\UpdateUserProfileInformation; +use App\Models\InstanceSettings; use App\Models\User; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Http\Request; @@ -29,8 +30,21 @@ class FortifyServiceProvider extends ServiceProvider */ public function boot(): void { - Fortify::loginView(fn () => view('auth.login')); - Fortify::registerView(fn () => view('auth.register')); + Fortify::registerView(function () { + $settings = InstanceSettings::find(0); + if (!$settings->is_registration_enabled) { + abort(403); + } + return view('auth.register'); + }); + + Fortify::loginView(function () { + $settings = InstanceSettings::find(0); + return view('auth.login', [ + 'is_registration_enabled' => $settings->is_registration_enabled + ]); + }); + Fortify::authenticateUsing(function (Request $request) { $user = User::where('email', $request->email)->with('teams')->first(); if ( @@ -49,12 +63,11 @@ class FortifyServiceProvider extends ServiceProvider RateLimiter::for('login', function (Request $request) { $email = (string) $request->email; - return Limit::perMinute(5)->by($email.$request->ip()); + return Limit::perMinute(5)->by($email . $request->ip()); }); RateLimiter::for('two-factor', function (Request $request) { return Limit::perMinute(5)->by($request->session()->get('login.id')); }); - } } diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index 4d6140a89..6ec6357b7 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -23,8 +23,8 @@ * @endif - @endif diff --git a/resources/views/components/layout.blade.php b/resources/views/components/layout.blade.php index 82a04bfb7..118c9ce50 100644 --- a/resources/views/components/layout.blade.php +++ b/resources/views/components/layout.blade.php @@ -7,7 +7,11 @@