src/Controller/SecurityController.php line 16

Open in your IDE?
  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. use Symfony\Contracts\Translation\TranslatorInterface;
  8. #[Route('/{_locale}'requirements: ['_locale' => '%allowedLocales%'])]
  9. class SecurityController extends AbstractController
  10. {
  11.     #[Route('/login'name'app_login')]
  12.     public function login(AuthenticationUtils $authenticationUtilsTranslatorInterface $translator): Response
  13.     {
  14.         // if ($this->getUser()) {
  15.         //     return $this->redirectToRoute('target_path');
  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('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
  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' => 'messages',
  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' => '<h1>'.$translator->trans('app.back.name').'</h1>',
  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('back_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' => 'Password',
  45.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  46.             'sign_in_label' => 'Log in',
  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('app_forgot_password_request'),
  55.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  56.             'forgot_password_label' => 'resetPassword.title',
  57.             // whether to enable or not the "remember me" checkbox (default: false)
  58.             'remember_me_enabled' => false,
  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' => true,
  63.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  64.             'remember_me_label' => 'Remember me',
  65.         ]);
  66.     }
  67.     /**
  68.      * @Route("/logout", name="app_logout")
  69.      */
  70.     public function logout(): void
  71.     {
  72.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  73.     }
  74. }