Skip to content

Commit

Permalink
Fixed 2FA TOTP for non-admins, while also retaining validation of aut…
Browse files Browse the repository at this point in the history
…h code

This fixes issue #717
  • Loading branch information
jbtronics committed Oct 13, 2024
1 parent 49acf3e commit a29d933
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Controller/UserSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function userSettings(Request $request, EntityManagerInterface $em, UserP
$google_form->handleRequest($request);

//We do not need to check for validity of the google form here, because we do not care if the other fields are valid
if (!$this->demo_mode && !$user->isSamlUser() && $google_form->isSubmitted()) {
if (!$this->demo_mode && !$user->isSamlUser() && $google_form->isSubmitted() && $google_form->isValid()) {
if (!$google_enabled) {
//Save 2FA settings (save secrets)
$user->setGoogleAuthenticatorSecret($google_form->get('googleAuthenticatorSecret')->getData());
Expand Down
3 changes: 2 additions & 1 deletion src/Form/TFAGoogleSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'pattern' => '\d*',
'autocomplete' => 'off',
],
'constraints' => [new ValidGoogleAuthCode()],
'constraints' => [new ValidGoogleAuthCode(groups: ["google_authenticator"])],
]
);

Expand Down Expand Up @@ -92,6 +92,7 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
'validation_groups' => ['google_authenticator'],
]);
}
}

0 comments on commit a29d933

Please sign in to comment.