components([ TextInput::make('login') ->label('Nama Pengguna atau Alamat Surel') ->placeholder('johndoe@example.com') ->required() ->autocomplete(false) ->autofocus(), TextInput::make('password') ->label('Kata Sandi') ->placeholder('********') ->password() ->revealable(filament()->arePasswordsRevealable()) ->required() ->autocomplete(false) ->extraInputAttributes(['tabindex' => 2]) ->hint( filament()->hasPasswordReset() ? new HtmlString(Blade::render('{{ __(\'filament-panels::auth/pages/login.actions.request_password_reset.label\') }}')) : null ), ]); } protected function getCredentialsFromFormData(#[SensitiveParameter] array $data): array { $loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; return [ $loginType => $data['login'], 'password' => $data['password'], ]; } public function authenticate(): ?LoginResponse { try { $this->rateLimit(5); } catch (TooManyRequestsException $exception) { $this->getRateLimitedNotification($exception)?->send(); return null; } $data = $this->form->getState(); $authGuard = Filament::auth(); $authProvider = $authGuard->getProvider(); /** @phpstan-ignore-line */ $credentials = $this->getCredentialsFromFormData($data); $user = $authProvider->retrieveByCredentials($credentials); if ((! $user) || (! $authProvider->validateCredentials($user, $credentials))) { $this->userUndertakingMultiFactorAuthentication = null; $this->fireFailedEvent($authGuard, $user, $credentials); $this->throwFailureValidationException(); } if ($user->is_active === IsActive::Inactive) { SystemNotification::danger( 'Akses Ditangguhkan ⛔', 'Maaf, Anda tidak dapat masuk karena status akun saat ini sedang tidak aktif. Silakan hubungi Administrator untuk informasi lebih lanjut. 😴', 'Akses Akun Terbatas', 'Akun Anda saat ini dalam status tidak aktif. Mohon hubungi pihak Administrator untuk klarifikasi lebih lanjut.' )->send(); throw ValidationException::withMessages([ 'login' => 'Akun Anda sedang dinonaktifkan.', ]); } if ( filled($this->userUndertakingMultiFactorAuthentication) && (decrypt($this->userUndertakingMultiFactorAuthentication) === $user->getAuthIdentifier()) ) { $this->multiFactorChallengeForm->validate(); } else { foreach (Filament::getMultiFactorAuthenticationProviders() as $multiFactorAuthenticationProvider) { if (! $multiFactorAuthenticationProvider->isEnabled($user)) { continue; } $this->userUndertakingMultiFactorAuthentication = encrypt($user->getAuthIdentifier()); if ($multiFactorAuthenticationProvider instanceof HasBeforeChallengeHook) { $multiFactorAuthenticationProvider->beforeChallenge($user); } break; } if (filled($this->userUndertakingMultiFactorAuthentication)) { $this->multiFactorChallengeForm->fill(); return null; } } if (! $authGuard->attemptWhen($credentials, function (Authenticatable $user): bool { if (! ($user instanceof FilamentUser)) { return true; } return $user->canAccessPanel(Filament::getCurrentOrDefaultPanel()); }, $data['remember'] ?? false)) { $this->fireFailedEvent($authGuard, $user, $credentials); $this->throwFailureValidationException(); } session()->regenerate(); SystemNotification::success( 'Berhasil Masuk ✨', 'Selamat datang kembali, '.$user->name.'. Sesi Anda telah berhasil diaktifkan dengan aman. 👋', 'Otentikasi Berhasil', 'Selamat datang, '.$user->name.'. Sesi autentikasi Anda telah berhasil dikonfirmasi oleh sistem.' )->send(); return app(LoginResponse::class); } protected function throwFailureValidationException(): never { SystemNotification::danger( 'Gagal Masuk 🚫', 'Terjadi kendala saat proses masuk. Mohon periksa kembali alamat surel atau kata sandi Anda. 😟', 'Otentikasi Gagal', 'Upaya masuk gagal dilakukan. Mohon lakukan verifikasi kembali pada kredensial yang Anda masukkan.' )->send(); throw ValidationException::withMessages([]); } }