fixing routes

This commit is contained in:
Saeed Vaziry
2024-10-07 00:18:11 +02:00
parent a94d1d42d2
commit 8bf1cc141e
22 changed files with 70 additions and 522 deletions

View File

@ -18,6 +18,8 @@ public function update(User $user, array $input): void
$user->save();
}
$user->refresh();
/** @var Project $firstProject */
$firstProject = $user->projects->first();
if (! $user->currentProject && $firstProject) {

View File

@ -1,19 +0,0 @@
<?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @method static void success(string $message)
* @method static void error(string $message)
* @method static void warning(string $message)
* @method static void info(string $message)
*/
class Toast extends Facade
{
protected static function getFacadeAccessor(): string
{
return 'toast';
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\Helpers;
class Toast
{
public function success(string $message): void
{
$this->toast('success', $message);
}
public function error(string $message): void
{
$this->toast('error', $message);
}
public function warning(string $message): void
{
$this->toast('warning', $message);
}
public function info(string $message): void
{
$this->toast('info', $message);
}
private function toast(string $type, string $message): void
{
session()->flash('toast.type', $type);
session()->flash('toast.message', $message);
}
}

View File

@ -5,6 +5,8 @@
use App\Enums\UserRole;
use App\Traits\HasTimezoneTimestamps;
use Carbon\Carbon;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@ -39,7 +41,7 @@
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class User extends Authenticatable
class User extends Authenticatable implements FilamentUser
{
use HasFactory;
use HasTimezoneTimestamps;
@ -157,4 +159,9 @@ public function allServers(): Builder
});
});
}
public function canAccessPanel(Panel $panel): bool
{
return true;
}
}

View File

@ -31,6 +31,6 @@ public function update(User $user, User $model): bool
public function delete(User $user, User $model): bool
{
return $user->isAdmin();
return $user->isAdmin() && $user->id !== $model->id;
}
}

View File

@ -5,10 +5,9 @@
use App\Helpers\FTP;
use App\Helpers\Notifier;
use App\Helpers\SSH;
use App\Helpers\Toast;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;
class AppServiceProvider extends ServiceProvider
{
@ -17,12 +16,9 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
//
Fortify::ignoreRoutes();
}
/**
* @throws BindingResolutionException
*/
public function boot(): void
{
ResourceCollection::withoutWrapping();
@ -34,9 +30,6 @@ public function boot(): void
$this->app->bind('notifier', function () {
return new Notifier;
});
$this->app->bind('toast', function () {
return new Toast;
});
$this->app->bind('ftp', function () {
return new FTP;
});

View File

@ -1,63 +0,0 @@
<?php
namespace App\Providers;
use App\Actions\User\ResetUserPassword;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
return Limit::perMinute(5)->by($throttleKey);
});
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
Fortify::loginView(function () {
return view('auth.login');
});
Fortify::requestPasswordResetLinkView(function () {
return view('auth.forgot-password');
});
Fortify::resetPasswordView(function (Request $request) {
return view('auth.reset-password', [
'token' => $request->route('token'),
'email' => $request->query('email'),
]);
});
Fortify::confirmPasswordView(function () {
return view('auth.confirm-password');
});
Fortify::twoFactorChallengeView(function () {
return view('auth.two-factor-challenge');
});
}
}

View File

@ -17,7 +17,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
public const HOME = '/app';
public const HOME = '/';
/**
* Define your route model bindings, pattern filters, and other route configuration.

View File

@ -80,7 +80,7 @@ public function panel(Panel $panel): Panel
return $panel
->default()
->id('app')
->path('app')
->path('')
->passwordReset()
->colors([
'primary' => Color::Indigo,

View File

@ -38,7 +38,7 @@ public function getWidgets(): array
protected function getHeaderActions(): array
{
return [
CreateAction::make()
CreateAction::make('create')
->label('Create User')
->icon('heroicon-o-plus')
->authorize('create', User::class)

View File

@ -87,13 +87,6 @@ public function getTable(): Table
->label('Projects')
->icon('heroicon-o-rectangle-stack')
->authorize(fn ($record) => auth()->user()->can('update', $record))
->action(function ($record, array $data) {
app(UpdateProjects::class)->update($record, $data);
Notification::make()
->title('Projects Updated')
->success()
->send();
})
->form(function (Form $form, $record) {
return $form
->schema([
@ -105,10 +98,17 @@ public function getTable(): Table
])
->columns(1);
})
->action(function ($record, array $data) {
app(UpdateProjects::class)->update($record, $data);
Notification::make()
->title('Projects Updated')
->success()
->send();
})
->modalSubmitActionLabel('Save')
->modalWidth(MaxWidth::Large),
DeleteAction::make()
->authorize(fn ($record) => auth()->user()->can('delete', $record)),
DeleteAction::make('delete')
->authorize(fn (User $record) => auth()->user()->can('delete', $record)),
]);
}
}