diff --git a/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RecoveryTokenController.php b/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RecoveryTokenController.php index 093b8ebfd..0354759ed 100644 --- a/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RecoveryTokenController.php +++ b/src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/RecoveryTokenController.php @@ -34,6 +34,7 @@ use Surfnet\StepupSelfService\SelfServiceBundle\Command\PromiseSafeStorePossessionCommand; use Surfnet\StepupSelfService\SelfServiceBundle\Command\RevokeRecoveryTokenCommand; use Surfnet\StepupSelfService\SelfServiceBundle\Exception\LogicException; +use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\RevokeRecoveryTokenType; use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\PromiseSafeStorePossessionType; use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService; use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\AuthenticationRequestFactory; @@ -47,6 +48,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Core\Exception\AuthenticationException; +use function sprintf; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -207,9 +209,9 @@ public function proveSmsPossession(Request $request): Response #[Route( path: '/recovery-token/delete/{recoveryTokenId}', name: 'ss_recovery_token_delete', - methods: ['GET'], + methods: ['GET', 'POST'], )] - public function delete(string $recoveryTokenId): Response + public function delete(Request $request, string $recoveryTokenId): Response { $this->assertRecoveryTokenInPossession($recoveryTokenId, $this->getUser()->getIdentity()); try { @@ -217,19 +219,32 @@ public function delete(string $recoveryTokenId): Response $command = new RevokeRecoveryTokenCommand(); $command->identity = $this->getUser()->getIdentity(); $command->recoveryToken = $recoveryToken; - $executionResult = $this->safeStoreService->revokeRecoveryToken($command); - if ($executionResult->getErrors() !== []) { - $this->addFlash('error', 'ss.form.recovery_token.delete.success'); - foreach ($executionResult->getErrors() as $error) { - $this->logger->error(sprintf('Recovery Token revocation failed with message: "%s"', $error)); + + $form = $this->createForm(RevokeRecoveryTokenType::class, $command)->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $executionResult = $this->safeStoreService->revokeRecoveryToken($command); + + if ($executionResult->isSuccessful()) { + $this->addFlash('error', 'ss.form.recovery_token.delete.success'); + } else { + foreach ($executionResult->getErrors() as $error) { + $this->logger->error(sprintf('Recovery Token revocation failed with message: "%s"', $error)); + } + $this->addFlash('error', 'ss.form.recovery_token.delete.failed'); } - return $this->redirect($this->generateUrl('ss_second_factor_list')); + return $this->redirectToRoute('ss_second_factor_list'); } } catch (NotFoundException) { throw new LogicException('Identity %s tried to remove an unpossessed recovery token'); } - $this->addFlash('success', 'ss.form.recovery_token.delete.success'); - return $this->redirect($this->generateUrl('ss_second_factor_list')); + return $this->render( + 'second_factor/revoke-recovery-token.html.twig', + [ + 'form' => $form->createView(), + 'recoveryTokenId' => $recoveryTokenId, + ] + ); } /** diff --git a/src/Surfnet/StepupSelfService/SelfServiceBundle/Form/Type/RevokeRecoveryTokenType.php b/src/Surfnet/StepupSelfService/SelfServiceBundle/Form/Type/RevokeRecoveryTokenType.php new file mode 100644 index 000000000..1de97fadd --- /dev/null +++ b/src/Surfnet/StepupSelfService/SelfServiceBundle/Form/Type/RevokeRecoveryTokenType.php @@ -0,0 +1,55 @@ +add('delete', SubmitType::class, [ + 'label' => 'ss.form.ss_revoke_recovery_token.revoke', + 'attr' => [ 'class' => 'btn btn-danger pull-right' ], + ]); + $builder->add('cancel', AnchorType::class, [ + 'label' => 'ss.form.ss_revoke_recovery_token.cancel', + 'attr' => [ 'class' => 'btn pull-right' ], + 'route' => 'ss_second_factor_list', + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => RevokeRecoveryTokenCommand::class, + ]); + } + + public function getBlockPrefix(): string + { + return 'ss_revoke_recovery_token'; + } +} diff --git a/templates/second_factor/revoke-recovery-token.html.twig b/templates/second_factor/revoke-recovery-token.html.twig new file mode 100644 index 000000000..c252cdc55 --- /dev/null +++ b/templates/second_factor/revoke-recovery-token.html.twig @@ -0,0 +1,21 @@ +{% extends "base.html.twig" %} +{% import _self as macro %} + +{% block page_title %}{{ 'ss.recovery_token.revoke.title'|trans }}{% endblock %} + +{% block content %} +
{{ 'ss.recovery_token.revoke.text.are_you_sure'|trans }}
+ +| {{ 'ss.recovery_token.revoke.table_header.recovery_token.identifier'|trans }} | +{{ recoveryTokenId }} | +
|---|