Skip to content

Commit 1c82f39

Browse files
committed
minor #949 Redirect to the right page after changing the locale in the login page (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #949). Discussion ---------- Redirect to the right page after changing the locale in the login page This fixes the problem reported in symfony/symfony-docs#10864 I don't think this is a Symfony bug or a Demo app bug ... I think it's an edge case for the reasons explained in the code ... and that's why I propose this solution. Commits ------- e493643 Redirect to the right page after changing the locale in the login page
2 parents df500dc + e493643 commit 1c82f39

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Controller/SecurityController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
namespace App\Controller;
1313

1414
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
15+
use Symfony\Component\HttpFoundation\Request;
1516
use Symfony\Component\HttpFoundation\Response;
1617
use Symfony\Component\Routing\Annotation\Route;
1718
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
19+
use Symfony\Component\Security\Http\Util\TargetPathTrait;
1820

1921
/**
2022
* Controller used to manage the application security.
@@ -25,11 +27,19 @@
2527
*/
2628
class SecurityController extends AbstractController
2729
{
30+
use TargetPathTrait;
31+
2832
/**
2933
* @Route("/login", name="security_login")
3034
*/
31-
public function login(AuthenticationUtils $helper): Response
35+
public function login(Request $request, AuthenticationUtils $helper): Response
3236
{
37+
// this statement solves an edge-case: if you change the locale in the login
38+
// page, after a successful login you are redirected to a page in the previous
39+
// locale. This code regenerates the referrer URL whenever the login page is
40+
// browsed, to ensure that its locale is always the current one.
41+
$this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));
42+
3343
return $this->render('security/login.html.twig', [
3444
// last username entered by the user (if any)
3545
'last_username' => $helper->getLastUsername(),

0 commit comments

Comments
 (0)