You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 satır
3.3KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\Security;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityAdminController extends AbstractController
  9. {
  10. /**
  11. * @Route("/login", name="sov_login")
  12. */
  13. public function login(AuthenticationUtils $authenticationUtils, Request $request): Response
  14. {
  15. if ($this->getUser()) {
  16. return $this->redirectToRoute('app_admin_dashboard');
  17. }
  18. // get the login error if there is one
  19. $error = $authenticationUtils->getLastAuthenticationError();
  20. // last username entered by the user
  21. $lastUsername = $authenticationUtils->getLastUsername();
  22. return $this->render('@EasyAdmin/page/login.html.twig', [
  23. // parameters usually defined in Symfony login forms
  24. 'error' => $error,
  25. 'last_username' => $lastUsername,
  26. // OPTIONAL parameters to customize the login form:
  27. // the translation_domain to use (define this option only if you are
  28. // rendering the login template in a regular Symfony controller; when
  29. // rendering it from an EasyAdmin Dashboard this is automatically set to
  30. // the same domain as the rest of the Dashboard)
  31. 'translation_domain' => 'admin',
  32. // the title visible above the login form (define this option only if you are
  33. // rendering the login template in a regular Symfony controller; when rendering
  34. // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  35. 'page_title' => '<img class="logo-admin" src="assets/img/' . $this->getParameter('app.admin.logo') . '" >',
  36. // the string used to generate the CSRF token. If you don't define
  37. // this parameter, the login form won't include a CSRF token
  38. 'csrf_token_intention' => 'authenticate',
  39. // the URL users are redirected to after the login (default: '/admin')
  40. 'target_path' => $this->generateUrl('app_admin_dashboard'),
  41. // the label displayed for the username form field (the |trans filter is applied to it)
  42. 'username_label' => 'Email',
  43. // the label displayed for the password form field (the |trans filter is applied to it)
  44. 'password_label' => 'Mot de passe',
  45. // the label displayed for the Sign In form button (the |trans filter is applied to it)
  46. 'sign_in_label' => 'Connexion',
  47. // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  48. 'username_parameter' => 'email',
  49. // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  50. 'password_parameter' => 'password',
  51. ]);
  52. }
  53. /**
  54. * @Route("/logout", name="sov_logout")
  55. */
  56. public function logout()
  57. {
  58. throw new \LogicException(
  59. 'This method can be blank - it will be intercepted by the logout key on your firewall.'
  60. );
  61. }
  62. }