Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions src/Livewire/Confirm2Fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,19 @@ protected function getFlashedData(): array

public function submit(): void
{
// Trigger form validation and retrieve state.
$this->form->getState();
// Trigger form validation and ensure fields are present.
$this->form->validate();

$user = $this->authenticate();

if (! $user) {
$this->redirect(Filament::getUrl());
} else {
if (app(FilamentTwoFactor::class,
[
'input' => $formData['totp_code'],
'safeDeviceInput' => isset($formData['safe_device_enable']) ? $formData['safe_device_enable'] : false
])->validate2Fa($user)) {
$sessionKey = config('filament-2fa.login.credential_key', '_2fa_login');

Notification::make()
->title('Success')
->body(__('filament-2fa::two-factor.success'))
->icon('heroicon-o-check-circle')
->color('success')
->send();

session()->forget("{$sessionKey}.credentials");
session()->forget("{$sessionKey}.remember");
session()->forget("{$sessionKey}.panel_id");

$this->redirectIntended(Filament::getUrl());
} else {
Filament::auth()->logout();
session()->regenerate();
$this->throwTotpcodeValidationException();
}

return;
}

$twoFactorValid = app(FilamentTwoFactor::class, [
// Use input field names so the TwoFactor service pulls values from the request.
'input' => 'totp_code',
'safeDeviceInput' => 'safe_device_enable',
])->validate($user);
Expand Down