|
16 | 16 | use App\Form\UserType;
|
17 | 17 | use Doctrine\ORM\EntityManagerInterface;
|
18 | 18 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
| 19 | +use Symfony\Bundle\SecurityBundle\Security; |
19 | 20 | use Symfony\Component\HttpFoundation\Request;
|
20 | 21 | use Symfony\Component\HttpFoundation\Response;
|
21 | 22 | use Symfony\Component\Routing\Annotation\Route;
|
22 | 23 | use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
23 | 24 | use Symfony\Component\Security\Http\Attribute\IsGranted;
|
24 |
| -use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; |
25 | 25 |
|
26 | 26 | /**
|
27 | 27 | * Controller used to manage current user. The #[CurrentUser] attribute
|
@@ -62,15 +62,19 @@ public function changePassword(
|
62 | 62 | #[CurrentUser] User $user,
|
63 | 63 | Request $request,
|
64 | 64 | EntityManagerInterface $entityManager,
|
65 |
| - LogoutUrlGenerator $logoutUrlGenerator, |
| 65 | + Security $security, |
66 | 66 | ): Response {
|
67 | 67 | $form = $this->createForm(ChangePasswordType::class, $user);
|
68 | 68 | $form->handleRequest($request);
|
69 | 69 |
|
70 | 70 | if ($form->isSubmitted() && $form->isValid()) {
|
71 | 71 | $entityManager->flush();
|
72 | 72 |
|
73 |
| - return $this->redirect($logoutUrlGenerator->getLogoutPath()); |
| 73 | + // The second argument is to disable CSRF protection before logout. |
| 74 | + // A CSRF token is already verified by the form. |
| 75 | + $security->logout(false); |
| 76 | + |
| 77 | + return $this->redirectToRoute('security_login'); |
74 | 78 | }
|
75 | 79 |
|
76 | 80 | return $this->render('user/change_password.html.twig', [
|
|
0 commit comments