src/Controller/SecurityController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  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'login')]
  11.     public function index(AuthenticationUtils $authenticationUtilsAdminUrlGenerator $adminUrlGenerator): Response
  12.     {
  13.         // get the login error if there is one
  14.         $error $authenticationUtils->getLastAuthenticationError();
  15.         // last username entered by the user
  16.         $lastUsername $authenticationUtils->getLastUsername();
  17.         return $this->render('@EasyAdmin/page/login.html.twig', [
  18.         //return $this->render('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' => 'messages',
  28.             // the title visible above the login form (define this option only if you are
  29.             // rendering the login template in a regular Symfony controller; when rendering
  30.             // it from an EasyAdmin Dashboard this is automatically set as the Dashboard title)
  31.             //'page_title' => 'page.login.title',
  32.             'page_title' => '<div><img src="/images/app/logo/collox/logo_424_220.png"></div>',
  33.             // the string used to generate the CSRF token. If you don't define
  34.             // this parameter, the login form won't include a CSRF token
  35.             'csrf_token_intention' => 'authenticate',
  36.             // the URL users are redirected to after the login (default: '/admin')
  37.             //'target_path' => $this->generateUrl('after_login'),
  38.             'target_path' => $adminUrlGenerator->generateUrl('admin_info_home'),
  39.             //'target_path' => $this->generateUrl('admin_dashboard'),
  40.             //'target_path' => $adminUrlGenerator->setController(UserCrudController::class)->setAction(Action::DETAIL)->generateUrl(),
  41.             //'target_path' => $adminUrlGenerator->setController(UserCrudController::class)->setAction(Action::DETAIL)->setEntityId($this->context->getEntity()->getPrimaryKeyValue())->generateUrl(),
  42.             //'target_path' => $this->generateUrl('user_profile_detail'),
  43.             // the label displayed for the username form field (the |trans filter is applied to it)
  44.             'username_label' => 'form.login.field.username.label',
  45.             // the label displayed for the password form field (the |trans filter is applied to it)
  46.             'password_label' => 'form.login.field.password.label',
  47.             // the label displayed for the Sign In form button (the |trans filter is applied to it)
  48.             'sign_in_label' => 'form.login.field.signIn.label',
  49.             // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  50.             'username_parameter' => '_username',
  51.             // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  52.             'password_parameter' => '_password',
  53.             // whether to enable or not the "forgot password?" link (default: false)
  54.             'forgot_password_enabled' => false,
  55.             // the path (i.e. a relative or absolute URL) to visit when clicking the "forgot password?" link (default: '#')
  56.             //'forgot_password_path' => $this->generateUrl('...', ['...' => '...']),
  57.             // the label displayed for the "forgot password?" link (the |trans filter is applied to it)
  58.             //'forgot_password_label' => 'Forgot your password?',
  59.             // whether to enable or not the "remember me" checkbox (default: false)
  60.             'remember_me_enabled' => true,
  61.             // remember me name form field (default: '_remember_me')
  62.             'remember_me_parameter' => '_remember_me',
  63.             // whether to check by default the "remember me" checkbox (default: false)
  64.             'remember_me_checked' => true,
  65.             // the label displayed for the remember me checkbox (the |trans filter is applied to it)
  66.             'remember_me_label' => 'form.login.field.rememberMe.label',
  67.         ]);
  68.     }
  69.     #[Route('/logout'name'logout'methods: ['GET'])]
  70.     public function logout()
  71.     {
  72.         // controller can be blank: it will never be called!
  73.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  74.     }
  75. }