otpService = $otpService; } public function mount(): void { if (Filament::auth()->check()) { redirect()->intended(Filament::getUrl()); } } public function back(): void { $this->otpSent = false; $this->otp = ''; } public function requestOtp(): void { $this->validate(['email' => 'required|email']); try { $this->rateLimit(5); } catch (TooManyRequestsException) { throw ValidationException::withMessages([ 'email' => 'Too many attempts. Please wait before trying again.', ]); } $this->otpService->generateAndSend($this->email); $this->otpSent = true; } public function authenticate(): void { $this->validate(['otp' => 'required']); try { $this->rateLimit(5); } catch (TooManyRequestsException) { throw ValidationException::withMessages([ 'otp' => 'Too many attempts. Please wait before trying again.', ]); } $staff = $this->otpService->validate($this->email, $this->otp); if (!$staff) { throw ValidationException::withMessages([ 'otp' => 'Invalid or expired code.', ]); } if ($staff instanceof FilamentUser && !$staff->canAccessPanel(Filament::getCurrentPanel())) { throw ValidationException::withMessages([ 'email' => 'You do not have access to this panel.', ]); } Filament::auth()->login($staff); session()->regenerate(); redirect()->intended(Filament::getUrl()); } public function getTitle(): string | Htmlable { return 'Sign in'; } public function getHeading(): string | Htmlable { return 'Sign in to your account'; } }