settings view

This commit is contained in:
Andras Bacsai
2023-04-25 10:06:45 +02:00
parent 07c952d75b
commit 50316c9cf6
10 changed files with 119 additions and 23 deletions

View File

@@ -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' => [

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Http\Livewire;
use App\Models\InstanceSettings as ModelsInstanceSettings;
use Livewire\Component;
class InstanceSettings extends Component
{
public ModelsInstanceSettings $settings;
public $do_not_track;
public $is_auto_update_enabled;
public $is_registration_enabled;
public $is_https_forced;
protected $rules = [
'settings.fqdn' => '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();
}
}

View File

@@ -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'));
});
}
}