eaa05d68c1
- Filament v5 multiFactorAuthentication enabled on both panels (App + Email) - HasAppAuthentication + HasEmailAuthentication on User and SuperAdmin - Migration: app_authentication_secret + recovery_codes + email_authentication_at - Sanctum REST API: /api/v1/login, /me, clients, vehicles, work-orders - EnsureTokenMatchesTenant middleware blocks cross-tenant token usage - CsvImportExport service: clients + vehicles bulk via plain CSV - Import/Export buttons on Client + Vehicle list pages - ApiTokens page in tenant panel (generate/revoke + last-used) - BackupAllTenantsCommand + scheduler (daily 03:00, retain 14 days) - Background scheduler in entrypoint.sh
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Pages;
|
|
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
|
|
class ApiTokens extends Page
|
|
{
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-key';
|
|
|
|
protected static ?string $navigationLabel = 'API Tokens';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
|
|
|
protected static ?int $navigationSort = 95;
|
|
|
|
protected static ?string $title = 'API Tokens';
|
|
|
|
protected string $view = 'filament.tenant.pages.api-tokens';
|
|
|
|
public ?string $newToken = null;
|
|
|
|
public function getTokens(): array
|
|
{
|
|
$u = auth()->user();
|
|
if (! $u) return [];
|
|
return $u->tokens()->latest()->get()->map(fn ($t) => [
|
|
'id' => $t->id,
|
|
'name' => $t->name,
|
|
'last_used_at' => $t->last_used_at?->diffForHumans() ?? '—',
|
|
'created_at' => $t->created_at->diffForHumans(),
|
|
'abilities' => is_array($t->abilities) ? implode(', ', $t->abilities) : '*',
|
|
])->all();
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\Action::make('create')
|
|
->label('Generează token')
|
|
->icon('heroicon-m-plus')
|
|
->schema([
|
|
Forms\Components\TextInput::make('name')
|
|
->label('Nume (descriere)')
|
|
->required()
|
|
->placeholder('ex: app-mobil, integrare-erp'),
|
|
])
|
|
->action(function (array $data) {
|
|
$u = auth()->user();
|
|
if (! $u) return;
|
|
$token = $u->createToken($data['name']);
|
|
$this->newToken = $token->plainTextToken;
|
|
Notification::make()
|
|
->title('Token generat!')
|
|
->body('Copiază token-ul ACUM — nu va mai fi afișat.')
|
|
->success()
|
|
->persistent()
|
|
->send();
|
|
}),
|
|
];
|
|
}
|
|
|
|
public function deleteToken(int $id): void
|
|
{
|
|
$u = auth()->user();
|
|
if (! $u) return;
|
|
$u->tokens()->where('id', $id)->delete();
|
|
Notification::make()->title('Token revocat')->success()->send();
|
|
}
|
|
|
|
public function dismissNew(): void
|
|
{
|
|
$this->newToken = null;
|
|
}
|
|
}
|