Skip to content

Commit

Permalink
Redirect to the right page after changing the locale in the login page
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Feb 25, 2019
1 parent d59a50f commit e493643
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 e493643

Please sign in to comment.