File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1212namespace App \Controller ;
1313
1414use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
15+ use Symfony \Component \HttpFoundation \Request ;
1516use Symfony \Component \HttpFoundation \Response ;
1617use Symfony \Component \Routing \Annotation \Route ;
1718use Symfony \Component \Security \Http \Authentication \AuthenticationUtils ;
19+ use Symfony \Component \Security \Http \Util \TargetPathTrait ;
1820
1921/**
2022 * Controller used to manage the application security.
2527 */
2628class 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 (),
You can’t perform that action at this time.
0 commit comments