src/Controller/SecurityController.php line 90

  1. <?php
  2. namespace App\Controller;
  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 SecurityController extends AbstractController
  8. {
  9.     #[Route(path'/admin/login'name'app_login')]
  10.     public function login(AuthenticationUtils $authenticationUtils): Response
  11.     {
  12.         if ($this->getUser()) {
  13.             return $this->redirectToRoute('app_admin');
  14.         }
  15.         $error $authenticationUtils->getLastAuthenticationError();
  16.         $lastUsername $authenticationUtils->getLastUsername();
  17.         return $this->render('@EasyAdmin/page/login.html.twig', [
  18.             // parameters usually defined in Symfony login forms
  19.             'error' => $error,
  20.             'last_username' => $lastUsername,
  21.             // OPTIONAL parameters to customize the login form:
  22.             // the translation_domain to use (define this option only if you are
  23.             // rendering the login template in a regular Symfony controller; when
  24.             // rendering it from an EasyAdmin Dashboard this is automatically set to
  25.             // the same domain as the rest of the Dashboard)
  26.             'translation_domain' => 'admin',
  27.             // by default EasyAdmin displays a black square as its default favicon;
  28.             // use this method to display a custom favicon: the given path is passed
  29.             // "as is" to the Twig asset() function:
  30.             // <link rel="shortcut icon" href="{{ asset('...') }}">
  31.             'favicon_path' => '/favicon.ico',
  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' => 'Logowanie CRM - Biuro',
  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' => '/secure_area',
  41.             // the label displayed for the username form field (the |trans filter is applied to it)
  42.             'username_label' => 'Twój użytkownik',
  43.             // the label displayed for the password form field (the |trans filter is applied to it)
  44.             'password_label' => 'Twoje hasło',
  45.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  46.             'sign_in_label' => 'Zaloguj się',
  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.             // whether to enable or not the "forgot password?" link (default: false)
  52.             //'forgot_password_enabled' => true,
  53.             // the path (i.e. a relative or absolute URL) to visit when clicking the "forgot password?" link (default: '#')
  54.             //'forgot_password_path' => $this->generateUrl('...', ['...' => '...']),
  55.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  56.            // 'forgot_password_label' => 'Forgot your password?',
  57.             // whether to enable or not the "remember me" checkbox (default: false)
  58.             'remember_me_enabled' => true,
  59.             // remember me name form field (default: '_remember_me')
  60.             //'remember_me_parameter' => 'custom_remember_me_param',
  61.             // whether to check by default the "remember me" checkbox (default: false)
  62.             'remember_me_checked' => false,
  63.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  64.             'remember_me_label' => 'Zapamiętaj mnie',
  65.         ]);
  66.     }
  67.     #[Route(path'/consultant/login'name'app_consultant_login')]
  68.     public function consultantLogin(AuthenticationUtils $authenticationUtils): Response
  69.     {
  70.         if ($this->getUser()) {
  71.             return $this->redirectToRoute('app_consultant');
  72.         }
  73.         $error $authenticationUtils->getLastAuthenticationError();
  74.         $lastUsername $authenticationUtils->getLastUsername();
  75.         return $this->render('@EasyAdmin/page/login.html.twig', [
  76.             // parameters usually defined in Symfony login forms
  77.             'error' => $error,
  78.             'last_username' => $lastUsername,
  79.             'translation_domain' => 'consultant',
  80.             'favicon_path' => '/favicon.ico',
  81.             'page_title' => 'Logowanie CRM - Obsługa klienta',
  82.             'csrf_token_intention' => 'authenticate',
  83.             'target_path' => '/consultant',
  84.             'username_label' => 'Twój użytkownik',
  85.             'password_label' => 'Twoje hasło',
  86.             'sign_in_label' => 'Zaloguj się',
  87.             'username_parameter' => 'email',
  88.             'password_parameter' => 'password',
  89.         ]);
  90.     }
  91.     #[Route(path'/admin/logout'name'app_logout')]
  92.     public function logout(): void
  93.     {
  94.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  95.     }
  96.     #[Route(path'/consultant/logout'name'app_consultant_logout')]
  97.     public function logoutConsultant(): void
  98.     {
  99.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  100.     }
  101. }