From 68a4a29a4f30c72cef372fc3a074ebb6640c712c Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 27 Nov 2025 11:14:29 +0700 Subject: [PATCH] feat(register): implement custom register and user must verify email --- app/Filament/Pages/CustomRegistration.php | 71 +++++++++++++++++++ app/Models/User.php | 5 +- .../Filament/DashboardPanelProvider.php | 2 + 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 app/Filament/Pages/CustomRegistration.php diff --git a/app/Filament/Pages/CustomRegistration.php b/app/Filament/Pages/CustomRegistration.php new file mode 100644 index 0000000..ee52bab --- /dev/null +++ b/app/Filament/Pages/CustomRegistration.php @@ -0,0 +1,71 @@ +components([ + TextInput::make('name') + ->label('Nama') + ->placeholder('John Doe') + ->autocomplete(false) + ->autofocus() + ->required() + ->maxLength(100), + + TextInput::make('email') + ->label('Alamat Surel') + ->placeholder('johndoe@example.com') + ->autocomplete(false) + ->required() + ->maxLength(254) + ->unique() + ->email(), + + TextInput::make('username') + ->label('Nama Pengguna') + ->placeholder('johndoe') + ->autocomplete(false) + ->required() + ->minLength(5) + ->maxLength(20) + ->regex('/^[a-zA-Z0-9_.-]+$/') + ->unique(), + + TextInput::make('password') + ->label('Kata Sandi') + ->password() + ->revealable(filament()->arePasswordsRevealable()) + ->required() + ->rule(Password::default()) + ->autocomplete(false) + ->dehydrated(fn ($state): bool => filled($state)) + ->dehydrateStateUsing(fn ($state): string => Hash::make($state)) + ->placeholder('********'), + ]); + } + + protected function handleRegistration(array $data): Model + { + $user = $this->getUserModel()::create($data); + $user->assignRole('Perusahaan'); + + return $user; + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 7bce754..d7506e8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,11 +2,10 @@ namespace App\Models; -// use Illuminate\Contracts\Auth\MustVerifyEmail; - use App\Enums\IsActive; use Filament\Models\Contracts\FilamentUser; use Filament\Panel; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Attributes\Scope; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\SoftDeletes; @@ -14,7 +13,7 @@ use Illuminate\Notifications\Notifiable; use Spatie\Permission\Traits\HasRoles; -class User extends Authenticatable implements FilamentUser +class User extends Authenticatable implements FilamentUser, MustVerifyEmail { use HasRoles, Notifiable, SoftDeletes; diff --git a/app/Providers/Filament/DashboardPanelProvider.php b/app/Providers/Filament/DashboardPanelProvider.php index e85db97..d76449e 100644 --- a/app/Providers/Filament/DashboardPanelProvider.php +++ b/app/Providers/Filament/DashboardPanelProvider.php @@ -3,6 +3,7 @@ namespace App\Providers\Filament; use App\Filament\Pages\CustomLogin; +use App\Filament\Pages\CustomRegistration; use BezhanSalleh\FilamentShield\FilamentShieldPlugin; use Filament\Http\Middleware\Authenticate; use Filament\Http\Middleware\AuthenticateSession; @@ -47,6 +48,7 @@ public function panel(Panel $panel): Panel ->id('dashboard') ->path('dashboard') ->login(CustomLogin::class) + ->registration(CustomRegistration::class) ->colors([ 'primary' => Color::Blue, ])