src/Controller/Admin/SecurityController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use RuntimeException;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10.     #[Route('/login'name'app_login')]
  11.     public function login(AuthenticationUtils $authenticationUtils): Response
  12.     {
  13.         if ($this->getUser()) {
  14.             return $this->redirectToRoute('admin');
  15.         }
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         $lastUsername $authenticationUtils->getLastUsername();
  18.         return $this->render('@EasyAdmin/page/login.html.twig', [
  19.             // parameters usually defined in Symfony login forms
  20.             'error' => $error,
  21.             'last_username' => $lastUsername,
  22.             // OPTIONAL parameters to customize the login form:
  23.             // the translation_domain to use (define this option only if you are
  24.             // rendering the login template in a regular Symfony controller; when
  25.             // rendering it from an EasyAdmin Dashboard this is automatically set to
  26.             // the same domain as the rest of the Dashboard)
  27.             'translation_domain' => 'admin',
  28.             // by default EasyAdmin displays a black square as its default favicon;
  29.             // use this method to display a custom favicon: the given path is passed
  30.             // "as is" to the Twig asset() function:
  31.             // <link rel="shortcut icon" href="{{ asset('...') }}">
  32.             'favicon_path' => '/favicon-admin.svg',
  33.             // the title visible above the login form (define this option only if you are
  34.             // rendering the login template in a regular Symfony controller; when rendering
  35.             // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  36. //            'page_title' => 'Joue Concours Admin',
  37.             // the string used to generate the CSRF token. If you don't define
  38.             // this parameter, the login form won't include a CSRF token
  39.             'csrf_token_intention' => 'authenticate',
  40.             // the URL users are redirected to after the login (default: '/admin')
  41.             'target_path' => $this->generateUrl('admin'),
  42.             // the label displayed for the username form field (the |trans filter is applied to it)
  43.             'username_label' => 'Email',
  44.             // the label displayed for the password form field (the |trans filter is applied to it)
  45.             'password_label' => 'Password',
  46.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  47.             'sign_in_label' => 'Sign In',
  48.             // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  49. //            'username_parameter' => 'my_custom_username_field',
  50.             // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  51. //            'password_parameter' => 'my_custom_password_field',
  52.             // whether to enable or not the "forgot password?" link (default: false)
  53.             'forgot_password_enabled' => true,
  54.             // the path (i.e. a relative or absolute URL) to visit when clicking the "forgot password?" link (default: '#')
  55.             'forgot_password_path' => $this->generateUrl('app_forgot_password_request'),
  56.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  57.             'forgot_password_label' => 'forgot password?',
  58.             // whether to enable or not the "remember me" checkbox (default: false)
  59.             'remember_me_enabled' => true,
  60.             // remember me name form field (default: '_remember_me')
  61. //            'remember_me_parameter' => 'custom_remember_me_param',
  62.             // whether to check by default the "remember me" checkbox (default: false)
  63.             'remember_me_checked' => true,
  64.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  65.             'remember_me_label' => 'Remember me',
  66.         ]);
  67.     }
  68.     /**
  69.      * @throws RuntimeException
  70.      */
  71.     #[Route('/logout'name'app_logout')]
  72.     public function logout()
  73.     {
  74.         // controller can be blank: it will never be called!
  75.         throw new RuntimeException('Don\'t forget to activate logout in security.yaml');
  76.     }
  77. }