feat(register): implement custom register and user must verify email
This commit is contained in:
parent
fdda62b2a5
commit
68a4a29a4f
71
app/Filament/Pages/CustomRegistration.php
Normal file
71
app/Filament/Pages/CustomRegistration.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Auth\Pages\Register;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class CustomRegistration extends Register
|
||||
{
|
||||
public function getHeading(): string|Htmlable
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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,
|
||||
])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user