Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SonataIntegrationBundle] Handle 2FA totp secret empty submission #216

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ public function enable2faAction(
return new RedirectResponse($this->admin->generateObjectUrl('disable-2fa', $user));
}

$user->setTotpSecret($enable2fa->totpSecret);
if ($totpAuthenticator->checkCode($user, $enable2fa->code)) {
$user->enableTwoFActorAuthenticationProvider('totp');
$this->admin->getModelManager()->update($user);

$this->addFlash(
'sonata_flash_success',
$this->trans('admin.flash.2fa_enabled', [], 'DrawUserBundle')
);

return $this->redirectTo($request, $user);
if ($enable2fa->totpSecret) {
$user->setTotpSecret($enable2fa->totpSecret);
if ($totpAuthenticator->checkCode($user, $enable2fa->code)) {
$user->enableTwoFActorAuthenticationProvider('totp');
$this->admin->getModelManager()->update($user);

$this->addFlash(
'sonata_flash_success',
$this->trans('admin.flash.2fa_enabled', [], 'DrawUserBundle')
);

return $this->redirectTo($request, $user);
}
}

$this->addFlash(
Expand All @@ -74,6 +76,13 @@ public function enable2faAction(
$totpSecret = $user->getTotpSecret();
$enable2fa->totpSecret = $totpSecret;
$form->setData($enable2fa);
} elseif (!$user->getTotpSecret()) {
$this->addFlash(
'sonata_flash_error',
$this->trans('admin.flash.2fa_invalid_code_refreshed', [], 'DrawUserBundle')
);

return new RedirectResponse($this->admin->generateObjectUrl('enable-2fa', $user));
}

$qrCode = $qrCodeGenerator->getTotpQrCode($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ admin:
2fa_enabled: '2FA successfully enabled.'
2fa_disabled: '2FA successfully disabled.'
2fa_invalid_code: 'Invalid code provided. Please, try again.'
2fa_invalid_code_refreshed: 'Error with provided code. Please, try again. The code has been refreshed.'
list:
2fa_enabled: '2FA enabled'
form:
Expand Down
Loading