vendor/friendsofsymfony/user-bundle/Controller/SecurityController.php line 50

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSUserBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\UserBundle\Controller;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. /**
  16.  * Controller managing security.
  17.  *
  18.  * @author Thibault Duplessis <thibault.duplessis@gmail.com>
  19.  * @author Christophe Coevoet <stof@notk.org>
  20.  *
  21.  * @final
  22.  */
  23. class SecurityController extends AbstractController
  24. {
  25.     private $authenticationUtils;
  26.     private $tokenManager;
  27.     public function __construct(AuthenticationUtils $authenticationUtilsCsrfTokenManagerInterface $tokenManager null)
  28.     {
  29.         $this->authenticationUtils $authenticationUtils;
  30.         $this->tokenManager $tokenManager;
  31.     }
  32.     public function loginAction(): Response
  33.     {
  34.         $error $this->authenticationUtils->getLastAuthenticationError();
  35.         $lastUsername $this->authenticationUtils->getLastUsername();
  36.         $csrfToken $this->tokenManager
  37.             $this->tokenManager->getToken('authenticate')->getValue()
  38.             : null;
  39.         return $this->renderLogin([
  40.             'last_username' => $lastUsername,
  41.             'error' => $error,
  42.             'csrf_token' => $csrfToken,
  43.         ]);
  44.     }
  45.     public function checkAction()
  46.     {
  47.         throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
  48.     }
  49.     public function logoutAction()
  50.     {
  51.         throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
  52.     }
  53.     /**
  54.      * Renders the login template with the given parameters. Overwrite this function in
  55.      * an extended controller to provide additional data for the login template.
  56.      */
  57.     protected function renderLogin(array $data): Response
  58.     {
  59.         return $this->render('@FOSUser/Security/login.html.twig'$data);
  60.     }
  61. }