src/Controller/SecurityController.php line 13

Open in your IDE?
  1. <?php 
  2. // src/Controller/SecurityController.php
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10.     #[Route('/login'name'app_login')]
  11.     public function index(AuthenticationUtils $authenticationUtils): Response
  12.     {
  13.         // redirect logged in users
  14.         if ($this->getUser()) {
  15.             return $this->redirectToRoute('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('security/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.             // by default EasyAdmin displays a black square as its default favicon;
  32.             // use this method to display a custom favicon: the given path is passed
  33.             // "as is" to the Twig asset() function:
  34.             // <link rel="shortcut icon" href="{{ asset('...') }}">
  35.             // 'favicon_path'          => '/favicon-admin.svg',
  36.             // the title visible above the login form (define this option only if you are
  37.             // rendering the login template in a regular Symfony controller; when rendering
  38.             // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  39.             'page_title'            => 'DG Golf <br/>Concierge',
  40.             // the string used to generate the CSRF token. If you don't define
  41.             // this parameter, the login form won't include a CSRF token
  42.             'csrf_token_intention'  => 'authenticate',
  43.             // set form action
  44.             'action'                => $this->generateUrl('app_login'),
  45.             // the URL users are redirected to after the login (default: '/admin')
  46.             'target_path'           => $this->generateUrl('dashboard'),
  47.             // the label displayed for the username form field (the |trans filter is applied to it)
  48.             'username_label'        => 'Username',
  49.             // the label displayed for the password form field (the |trans filter is applied to it)
  50.             'password_label'        => 'Password',
  51.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  52.             'sign_in_label'         => 'Sign in',
  53.             // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  54.             'username_parameter'    => '_username',
  55.             // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  56.             'password_parameter'    => '_password',
  57.             // whether to enable or not the "forgot password?" link (default: false)
  58.             'forgot_password_enabled' => true,
  59.             // the path (i.e. a relative or absolute URL) to visit when clicking the "forgot password?" link (default: '#')
  60.             'forgot_password_path'  => $this->generateUrl('app_forgot_password_request'),
  61.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  62.             'forgot_password_label' => 'Forgot password?',
  63.             // whether to enable or not the "remember me" checkbox (default: false)
  64.             'remember_me_enabled'   => true,
  65.             // remember me name form field (default: '_remember_me')
  66.             'remember_me_parameter' => '_remember_me',
  67.             // whether to check by default the "remember me" checkbox (default: false)
  68.             'remember_me_checked'   => true,
  69.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  70.             'remember_me_label'     => 'Remember me',
  71.         ]);
  72.     }
  73.     
  74.     #[Route('/logout'name'app_logout'methods: ['GET'])]
  75.     public function logout()
  76.     {
  77.         // controller can be blank: it will never be called!
  78.         throw new \Exception('Don\'t forget to logout');
  79.     }
  80. }