rateLimit(5); } catch (TooManyRequestsException $exception) { $seconds = is_numeric($exception->secondsUntilAvailable) ? (int) $exception->secondsUntilAvailable : 0; $minutes = ceil($seconds / 60); $body = null; $throttled = __('filament-panels::pages/auth/login.notifications.throttled'); if (is_array($throttled)) { $bodyText = __('filament-panels::pages/auth/login.notifications.throttled.body', [ 'seconds' => $seconds, 'minutes' => $minutes, ]); $body = is_string($bodyText) ? $bodyText : null; } Notification::make() ->title(__('filament-panels::pages/auth/login.notifications.throttled.title', [ 'seconds' => $seconds, 'minutes' => $minutes, ])) ->body($body) ->danger() ->send(); return null; } $data = $this->form->getState(); if (! Filament::auth()->attempt($this->getCredentialsFromFormData($data), (bool) ($data['remember'] ?? false))) { $this->throwFailureValidationException(); } $user = Filament::auth()->user(); if ( ($user instanceof FilamentUser) && ($panel = Filament::getCurrentOrDefaultPanel()) instanceof \Filament\Panel && (! $user->canAccessPanel($panel)) ) { Filament::auth()->logout(); $this->throwFailureValidationException(); } session()->regenerate(); return app(LoginResponse::class); } protected function throwFailureValidationException(): never { throw ValidationException::withMessages([ 'data.username' => __('filament-panels::pages/auth/login.messages.failed'), ]); } /** * @return array<\Illuminate\Contracts\Support\Htmlable|string> */ protected function getFormSchema(): array { return [ TextInput::make('username') ->label(__('filament::login.fields.username.label')) ->required() ->autocomplete(), TextInput::make('password') ->label(__('filament::login.fields.password.label')) ->password() ->required(), Checkbox::make('remember') ->label(__('filament::login.fields.remember.label')), ]; } #[\Override] protected function getEmailFormComponent(): Component { return TextInput::make('username') ->label(__('filament::login.fields.username.label')) ->required() ->autocomplete() ->autofocus() ->extraInputAttributes(['tabindex' => 1]); } /** * @param array $data * * @return array */ #[\Override] protected function getCredentialsFromFormData(array $data): array { return [ 'username' => $data['username'], 'password' => $data['password'], ]; } }