|
34 | 34 | use Surfnet\StepupSelfService\SelfServiceBundle\Command\PromiseSafeStorePossessionCommand; |
35 | 35 | use Surfnet\StepupSelfService\SelfServiceBundle\Command\RevokeRecoveryTokenCommand; |
36 | 36 | use Surfnet\StepupSelfService\SelfServiceBundle\Exception\LogicException; |
| 37 | +use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\RevokeRecoveryTokenType; |
37 | 38 | use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\PromiseSafeStorePossessionType; |
38 | 39 | use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService; |
39 | 40 | use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\AuthenticationRequestFactory; |
|
47 | 48 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
48 | 49 | use Symfony\Component\Routing\Attribute\Route; |
49 | 50 | use Symfony\Component\Security\Core\Exception\AuthenticationException; |
| 51 | +use function sprintf; |
50 | 52 |
|
51 | 53 | /** |
52 | 54 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
@@ -207,29 +209,42 @@ public function proveSmsPossession(Request $request): Response |
207 | 209 | #[Route( |
208 | 210 | path: '/recovery-token/delete/{recoveryTokenId}', |
209 | 211 | name: 'ss_recovery_token_delete', |
210 | | - methods: ['GET'], |
| 212 | + methods: ['GET', 'POST'], |
211 | 213 | )] |
212 | | - public function delete(string $recoveryTokenId): Response |
| 214 | + public function delete(Request $request, string $recoveryTokenId): Response |
213 | 215 | { |
214 | 216 | $this->assertRecoveryTokenInPossession($recoveryTokenId, $this->getUser()->getIdentity()); |
215 | 217 | try { |
216 | 218 | $recoveryToken = $this->recoveryTokenService->getRecoveryToken($recoveryTokenId); |
217 | 219 | $command = new RevokeRecoveryTokenCommand(); |
218 | 220 | $command->identity = $this->getUser()->getIdentity(); |
219 | 221 | $command->recoveryToken = $recoveryToken; |
220 | | - $executionResult = $this->safeStoreService->revokeRecoveryToken($command); |
221 | | - if ($executionResult->getErrors() !== []) { |
222 | | - $this->addFlash('error', 'ss.form.recovery_token.delete.success'); |
223 | | - foreach ($executionResult->getErrors() as $error) { |
224 | | - $this->logger->error(sprintf('Recovery Token revocation failed with message: "%s"', $error)); |
| 222 | + |
| 223 | + $form = $this->createForm(RevokeRecoveryTokenType::class, $command)->handleRequest($request); |
| 224 | + |
| 225 | + if ($form->isSubmitted() && $form->isValid()) { |
| 226 | + $executionResult = $this->safeStoreService->revokeRecoveryToken($command); |
| 227 | + |
| 228 | + if ($executionResult->isSuccessful()) { |
| 229 | + $this->addFlash('error', 'ss.form.recovery_token.delete.success'); |
| 230 | + } else { |
| 231 | + foreach ($executionResult->getErrors() as $error) { |
| 232 | + $this->logger->error(sprintf('Recovery Token revocation failed with message: "%s"', $error)); |
| 233 | + } |
| 234 | + $this->addFlash('error', 'ss.form.recovery_token.delete.failed'); |
225 | 235 | } |
226 | | - return $this->redirect($this->generateUrl('ss_second_factor_list')); |
| 236 | + return $this->redirectToRoute('ss_second_factor_list'); |
227 | 237 | } |
228 | 238 | } catch (NotFoundException) { |
229 | 239 | throw new LogicException('Identity %s tried to remove an unpossessed recovery token'); |
230 | 240 | } |
231 | | - $this->addFlash('success', 'ss.form.recovery_token.delete.success'); |
232 | | - return $this->redirect($this->generateUrl('ss_second_factor_list')); |
| 241 | + return $this->render( |
| 242 | + 'second_factor/revoke-recovery-token.html.twig', |
| 243 | + [ |
| 244 | + 'form' => $form->createView(), |
| 245 | + 'recoveryToken' => $recoveryToken, |
| 246 | + ] |
| 247 | + ); |
233 | 248 | } |
234 | 249 |
|
235 | 250 | /** |
|
0 commit comments