121 lines
5.0 KiB
PHP
121 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Auth;
|
|
|
|
use App\Filament\Support\CheerfulNotification;
|
|
use Filament\Auth\Pages\EditProfile;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\Width;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class Profile extends EditProfile
|
|
{
|
|
public function getMaxContentWidth(): Width
|
|
{
|
|
return Width::FourExtraLarge;
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Section::make()
|
|
->schema([
|
|
TextInput::make('name')
|
|
->label('Nama Lengkap')
|
|
->placeholder('Masukkan nama lengkap Anda')
|
|
->required()
|
|
->maxLength(100),
|
|
|
|
Grid::make(2)
|
|
->schema([
|
|
TextInput::make('email')
|
|
->label('Alamat Surel')
|
|
->placeholder('contoh@email.com')
|
|
->autocomplete(false)
|
|
->required()
|
|
->maxLength(254)
|
|
->unique(ignoreRecord: true)
|
|
->email()
|
|
->prefixIcon('heroicon-o-envelope')
|
|
->live(),
|
|
|
|
TextInput::make('username')
|
|
->label('Nama Pengguna')
|
|
->placeholder('nama_pengguna')
|
|
->autocomplete(false)
|
|
->required()
|
|
->minLength(5)
|
|
->maxLength(20)
|
|
->regex('/^[a-zA-Z0-9_.-]+$/')
|
|
->unique(ignoreRecord: true)
|
|
->prefixIcon('heroicon-o-at-symbol'),
|
|
]),
|
|
]),
|
|
|
|
Section::make()
|
|
->schema([
|
|
Grid::make(2)
|
|
->schema([
|
|
TextInput::make('password')
|
|
->label(__('filament-panels::auth/pages/register.form.password.label'))
|
|
->placeholder('********')
|
|
->password()
|
|
->revealable(filament()->arePasswordsRevealable())
|
|
->required(fn (Get $get) => filled($get('password')) || filled($get('passwordConfirmation')))
|
|
->rule(Password::default())
|
|
->showAllValidationMessages()
|
|
->dehydrated(fn ($state) => filled($state))
|
|
->dehydrateStateUsing(fn ($state) => Hash::make($state))
|
|
->same('passwordConfirmation')
|
|
->validationAttribute(__('filament-panels::auth/pages/register.form.password.validation_attribute'))
|
|
->prefixIcon('heroicon-o-lock-closed'),
|
|
|
|
TextInput::make('passwordConfirmation')
|
|
->label(__('filament-panels::auth/pages/register.form.password_confirmation.label'))
|
|
->placeholder('********')
|
|
->password()
|
|
->revealable(filament()->arePasswordsRevealable())
|
|
->required(fn (Get $get) => filled($get('password')) || filled($get('passwordConfirmation')))
|
|
->dehydrated(false)
|
|
->prefixIcon('heroicon-o-lock-closed'),
|
|
]),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
{
|
|
$record->update($data);
|
|
|
|
return $record;
|
|
}
|
|
|
|
protected function afterSave(): void
|
|
{
|
|
CheerfulNotification::success(
|
|
'Profil Diperbarui! ✨',
|
|
'Sip! Detail profil baru Anda sudah tersimpan dengan aman. Terus semangat ya! 💪😊'
|
|
)->send();
|
|
|
|
if (filled($this->form->getState()['password'] ?? null)) {
|
|
auth()->logout();
|
|
session()->invalidate();
|
|
session()->regenerateToken();
|
|
|
|
CheerfulNotification::info(
|
|
'Sesi Berakhir 🔐',
|
|
'Anda telah mengubah kata sandi. Silakan masuk kembali dengan kata sandi baru Anda ya. 😉👋'
|
|
)->send();
|
|
|
|
$this->redirect(filament()->getLoginUrl());
|
|
}
|
|
}
|
|
}
|