vendor/roothirsch/core-bundle/Security/Controller/SecurityController.php line 20

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\Security\Controller;
  3. use Psr\Http\Message\RequestInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  10. class SecurityController extends AbstractController
  11. {
  12. use TargetPathTrait;
  13. /**
  14. * @Route("/login", name="app_login")
  15. */
  16. public function login(AuthenticationUtils $authenticationUtils, Request $request): Response
  17. {
  18. $error = $authenticationUtils->getLastAuthenticationError();
  19. $lastUsername = $authenticationUtils->getLastUsername();
  20. if ($request->getMethod() == 'GET' && $request->get('return_url', false) !== false) {
  21. $this->saveTargetPath($request->getSession(), 'main', $request->get('return_url', false));
  22. }
  23. return $this->render(
  24. '@EasyAdmin/page/login.html.twig', [
  25. // parameters usually defined in Symfony login forms
  26. 'error' => $error,
  27. 'last_username' => $lastUsername,
  28. // the string used to generate the CSRF token. If you don't define
  29. // this parameter, the login form won't include a CSRF token
  30. 'csrf_token_intention' => 'authenticate',
  31. // the URL users are redirected to after the login (default: path('easyadmin'))
  32. 'target_path' => $this->getTargetPath($request->getSession(), 'main') ?? '/',
  33. // the label displayed for the username form field (the |trans filter is applied to it)
  34. 'username_label' => 'E-Mail-Adresse',
  35. // the label displayed for the password form field (the |trans filter is applied to it)
  36. 'password_label' => 'Passwort',
  37. // the label displayed for the Sign In form button (the |trans filter is applied to it)
  38. 'sign_in_label' => 'anmelden',
  39. // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  40. 'username_parameter' => 'username',
  41. // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  42. 'password_parameter' => 'password',
  43. ]
  44. );
  45. }
  46. /**
  47. * @Route("/logout", name="app_logout")
  48. */
  49. public function logout()
  50. {
  51. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  52. }
  53. }