src/Controller/Admin/SecurityController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Security\AdminFormAuthenticator;
  4. use LogicException;
  5. use Symfony\Bridge\Twig\Extension\TranslationExtension;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. /**
  11.  * @Route("/")
  12.  */
  13. class SecurityController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/login", name="app_login")
  17.      */
  18.     public function login(AuthenticationUtils $authenticationUtils): Response
  19.     {
  20.         if ($this->getUser()) {
  21.             return $this->redirectToRoute(AdminFormAuthenticator::DASHBOARD_ROUTE);
  22.         }
  23.         // get the login error if there is one
  24.         $error = $authenticationUtils->getLastAuthenticationError();
  25.         // last username entered by the user
  26.         $lastUsername = $authenticationUtils->getLastUsername();
  27.         return $this->render('security/login.html.twig', [
  28.                     'last_username' => $lastUsername,
  29.                     'error' => $error,
  30.                     // OPTIONAL parameters to customize the login form:
  31.                     // the translation_domain to use (define this option only if you are
  32.                     // rendering the login template in a regular Symfony controller; when
  33.                     // rendering it from an EasyAdmin Dashboard this is automatically set to
  34.                     // the same domain as the rest of the Dashboard)
  35.                     'translation_domain' => 'admin',
  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' => $this->get('twig')->getExtension(TranslationExtension::class)->trans('site.nume', [], 'admin'),
  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' => AdminFormAuthenticator::CSRF_TOKEN_KEY,
  43.                     // the URL users are redirected to after the login (default: '/admin')
  44.                     'target_path' => $this->generateUrl(AdminFormAuthenticator::DASHBOARD_ROUTE),
  45.                     // the label displayed for the username form field (the |trans filter is applied to it)
  46.                     'username_label' => 'page.login.email',
  47.                     // the label displayed for the password form field (the |trans filter is applied to it)
  48.                     'password_label' => 'page.login.parola',
  49.                     // the label displayed for the Sign In form button (the |trans filter is applied to it)
  50.                     'sign_in_label' => 'page.login.buton_login',
  51.                     // the 'name' HTML attribute of the <input> used for the username field (default: '_username')
  52.                     'username_parameter' => AdminFormAuthenticator::FIELD_USERNAME,
  53.                     // the 'name' HTML attribute of the <input> used for the password field (default: '_password')
  54.                     'password_parameter' => AdminFormAuthenticator::FIELD_PASSWORD,
  55.         ]);
  56.     }
  57.     /**
  58.      * @Route("/logout", name="app_logout")
  59.      */
  60.     public function logout()
  61.     {
  62.         throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  63.     }
  64. }