feat: Implement client authentication and pre-fill functionality
- Added AuthController for client login and token management. - Introduced AuthGate for handling authentication state and login UI. - Updated API to support fetching client data for pre-filling forms. - Modified App.vue to pre-fill client information if logged in. - Enhanced client model to include username and password fields. - Created migration for adding username and password to clients table. - Added utility for generating secure usernames and passwords. - Updated frontend to handle client tokens for pre-filling checkout forms. - Removed old CSS file and updated HTML references to new assets. - Added StatsOverview widget for displaying client and quote statistics. - Improved error handling and user feedback in the login process.
This commit is contained in:
@@ -3,10 +3,31 @@
|
||||
namespace App\Filament\Resources\ClienteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClienteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class CreateCliente extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ClienteResource::class;
|
||||
|
||||
protected ?string $plainPassword = null;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$this->plainPassword = $data['password'];
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
session()->flash('cliente_username_plain', $this->record->username);
|
||||
session()->flash('cliente_password_plain', $this->plainPassword);
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('view', ['record' => $this->getRecord()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,14 @@ namespace App\Filament\Resources\ClienteResource\Pages;
|
||||
use App\Filament\Resources\ClienteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class EditCliente extends EditRecord
|
||||
{
|
||||
protected static string $resource = ClienteResource::class;
|
||||
|
||||
protected ?string $plainPassword = null;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
@@ -17,4 +20,29 @@ class EditCliente extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
if (filled($data['password'] ?? null)) {
|
||||
$this->plainPassword = $data['password'];
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
} else {
|
||||
unset($data['password']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
if ($this->plainPassword !== null) {
|
||||
session()->flash('cliente_username_plain', $this->record->username);
|
||||
session()->flash('cliente_password_plain', $this->plainPassword);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('view', ['record' => $this->getRecord()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user