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.

SecurityAdminController.php 3.4KB

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