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\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 @@ public function register(): void
*/
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 @@ public function boot(): void
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'));
});
}
}

View File

@ -23,8 +23,8 @@
*
@endif
</label>
<input type="text" id={{ $name }} wire:model.defer={{ $name }} name={{ $name }}
@if ($required) required @endif
<input type={{ $type }} id={{ $name }} wire:model.defer={{ $name }}
name={{ $name }} @if ($required) required @endif
@if ($readonly) readOnly=true disabled=true @endif />
@endif

View File

@ -7,7 +7,11 @@
<title>{{ $title ?? 'Coolify' }}</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
@vite(['resources/js/app.js', 'resources/css/app.css'])
<style>[x-cloak] { display: none !important; }</style>
<style>
[x-cloak] {
display: none !important;
}
</style>
@livewireStyles
</head>

View File

@ -2,7 +2,11 @@
<div>v{{ config('coolify.version') }}</div>
@guest
<a href="/login">Login</a>
<a href="/register">Register</a>
@isset($isRegistrationEnabled)
<a href="/register">Register</a>
@else
<div>Registration disabled</div>
@endisset
@endguest
@auth
<a href="/">Home</a>

View File

@ -0,0 +1,23 @@
<div>
<form wire:submit.prevent='submit' class="flex flex-col">
<div class="flex flex-col gap-2 xl:flex-row">
<div class="flex flex-col w-96">
<x-input name="settings.fqdn" label="FQDN" />
<x-input name="settings.wildcard_domain" label="Wildcard Domain" />
</div>
<div class="flex flex-col w-96">
<x-input type="number" name="settings.public_port_min" label="Public Port Min" />
<x-input type="number" name="settings.public_port_max" label="Public Port Max" />
</div>
</div>
<button class="flex mx-auto mt-4" type="submit">
Submit
</button>
</form>
<div class="flex flex-col pt-4 text-right w-52">
<x-input instantSave type="checkbox" name="do_not_track" label="Do Not Track" />
<x-input instantSave type="checkbox" name="is_auto_update_enabled" label="Auto Update?" />
<x-input instantSave type="checkbox" name="is_registration_enabled" label="Registration Enabled?" />
<x-input instantSave type="checkbox" name="is_https_forced" label="Force https?" />
</div>
</div>

View File

@ -1,4 +1,4 @@
<x-layout>
<h1>Settings</h1>
<livewire:instance-settings :settings="$settings" />
</x-layout>

View File

@ -13,6 +13,6 @@
|
*/
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
// Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
// return (int) $user->id === (int) $id;
// });

View File

@ -14,19 +14,19 @@
|
*/
Artisan::command('inspire', function () {
// Artisan::command('inspire', function () {
$activity = Spatie\Activitylog\Models\Activity::latest()->first();
// $activity = Spatie\Activitylog\Models\Activity::latest()->first();
$this->info(
collect(
json_decode(data_get($activity, 'description'), associative: true, flags: JSON_THROW_ON_ERROR)
)
->sortBy('order')
->map(fn($i) => $i['output'])
->implode("\n")
);
// $this->info(
// collect(
// json_decode(data_get($activity, 'description'), associative: true, flags: JSON_THROW_ON_ERROR)
// )
// ->sortBy('order')
// ->map(fn($i) => $i['output'])
// ->implode("\n")
// );
})->purpose('Display an inspiring quote');
// })->purpose('Display an inspiring quote');