diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index f96d7cff0..eb849fcf1 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -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. @@ -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(),