Skip to content

Commit

Permalink
minor #949 Redirect to the right page after changing the locale in th…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
javiereguiluz committed Feb 25, 2019
2 parents df500dc + e493643 commit 1c82f39
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Http\Util\TargetPathTrait;

/**
* Controller used to manage the application security.
Expand All @@ -25,11 +27,19 @@
*/
class SecurityController extends AbstractController
{
use TargetPathTrait;

/**
* @Route("/login", name="security_login")
*/
public function login(AuthenticationUtils $helper): Response
public function login(Request $request, AuthenticationUtils $helper): Response
{
// this statement solves an edge-case: if you change the locale in the login
// page, after a successful login you are redirected to a page in the previous
// locale. This code regenerates the referrer URL whenever the login page is
// browsed, to ensure that its locale is always the current one.
$this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));

return $this->render('security/login.html.twig', [
// last username entered by the user (if any)
'last_username' => $helper->getLastUsername(),
Expand Down

0 comments on commit 1c82f39

Please sign in to comment.