src/UserBundle/Action/Security/Login.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of SolidInvoice project.
  5.  *
  6.  * (c) Pierre du Plessis <[email protected]>
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace SolidInvoice\UserBundle\Action\Security;
  12. use SolidInvoice\CoreBundle\Templating\Template;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  15. use Symfony\Component\Security\Core\Security;
  16. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  17. final class Login
  18. {
  19.     public function __invoke(Request $requestCsrfTokenManagerInterface $csrfTokenManager)
  20.     {
  21.         $session $request->getSession();
  22.         $authErrorKey Security::AUTHENTICATION_ERROR;
  23.         $lastUsernameKey Security::LAST_USERNAME;
  24.         $error null;
  25.         if ($request->attributes->has($authErrorKey)) {
  26.             $error $request->attributes->get($authErrorKey);
  27.         } elseif ($session->has($authErrorKey)) {
  28.             $error $session->get($authErrorKey);
  29.             $session->remove($authErrorKey);
  30.         }
  31.         if (! $error instanceof AuthenticationException) {
  32.             $error null// The value does not come from the security component.
  33.         }
  34.         return new Template(
  35.             '@SolidInvoiceUser/Security/login.html.twig',
  36.             [
  37.                 'last_username' => $session->get($lastUsernameKey),
  38.                 'error' => $error,
  39.                 'csrf_token' => $csrfTokenManager->getToken('authenticate')->getValue(),
  40.             ]
  41.         );
  42.     }
  43. }