src/Controller/SecurityController.php line 14

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.  
  8. class SecurityController extends AbstractController
  9. {
  10.     #[Route(path'/login'name'app_login')]
  11.     public function login(AuthenticationUtils $authenticationUtils): Response
  12.     {
  13.         // if ($this->getUser()) {
  14.         //     return $this->redirectToRoute('target_path');
  15.         // }
  16.         // get the login error if there is one
  17.         $error $authenticationUtils->getLastAuthenticationError();
  18.         // last username entered by the user
  19.         $lastUsername $authenticationUtils->getLastUsername();
  20.         return $this->render('security/login.html.twig', [
  21.             
  22.             'last_username' => $lastUsername,
  23.             // parameters usually defined in Symfony login forms
  24.             'error' => $error,
  25.             'last_username' => $lastUsername,
  26.     
  27.             // OPTIONAL parameters to customize the login form:
  28.     
  29.             // the translation_domain to use (define this option only if you are
  30.             // rendering the login template in a regular Symfony controller; when
  31.             // rendering it from an EasyAdmin Dashboard this is automatically set to
  32.             // the same domain as the rest of the Dashboard)
  33.             'translation_domain' => 'admin',
  34.     
  35.             // by default EasyAdmin displays a black square as its default favicon;
  36.             // use this method to display a custom favicon: the given path is passed
  37.             // "as is" to the Twig asset() function:
  38.             // <link rel="shortcut icon" href="{{ asset('...') }}">
  39.     
  40.            
  41.             'favicon_path' => "/bundles/assets/images/favicon.png",
  42.     
  43.             // the title visible above the login form (define this option only if you are
  44.             // rendering the login template in a regular Symfony controller; when rendering
  45.             // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  46.             'page_title' => '<img width="180" class="mb-3 mt-5" src="/bundles/assets/images/logo.png"  />',
  47.     
  48.             // the string used to generate the CSRF token. If you don't define
  49.             // this parameter, the login form won't include a CSRF token
  50.             'csrf_token_intention' => 'authenticate',
  51.     
  52.             // the URL users are redirected to after the login (default: '/admin')
  53.             //'target_path' => $this->generateUrl('admin'),
  54.     
  55.             // the label displayed for the username form field (the |trans filter is applied to it)
  56.             'username_label' => 'Email',
  57.     
  58.             // the label displayed for the password form field (the |trans filter is applied to it)
  59.             'password_label' => 'Mot de passe',
  60.     
  61.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  62.             'sign_in_label' => 'Se connecter',
  63.     
  64.             // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  65.             'username_parameter' => 'username',
  66.     
  67.             // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  68.             'password_parameter' => 'password',
  69.     
  70.             // whether to enable or not the "forgot password?" link (default: false)
  71.             'forgot_password_enabled' => false,
  72.     
  73.             // the path (i.e. a relative or absolute URL) to visit when clicking the "forgot password?" link (default: '#')
  74.             //'forgot_password_path' => $this->generateUrl('...', ['...' => '...']),
  75.     
  76.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  77.             'forgot_password_label' => 'Forgot your password?',
  78.     
  79.             // whether to enable or not the "remember me" checkbox (default: false)
  80.             'remember_me_enabled' => true,
  81.     
  82.             // remember me name form field (default: '_remember_me')
  83.             'remember_me_parameter' => 'remember_me',
  84.     
  85.             // whether to check by default the "remember me" checkbox (default: false)
  86.             'remember_me_checked' => false,
  87.     
  88.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  89.             'remember_me_label' => 'Se souvenir de moi',
  90.             
  91.             'error' => $error]);
  92.     }
  93.     #[Route(path'/logout'name'app_logout')]
  94.     public function logout(): void
  95.     {
  96.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  97.     }
  98. }