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

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.     /**
  33.      * @return Response
  34.      */
  35.     public function loginAction()
  36.     {
  37.         $error $this->authenticationUtils->getLastAuthenticationError();
  38.         $lastUsername $this->authenticationUtils->getLastUsername();
  39.         $csrfToken $this->tokenManager
  40.             $this->tokenManager->getToken('authenticate')->getValue()
  41.             : null;
  42.            
  43.        
  44.         return $this->renderLogin([
  45.             'last_username' => $lastUsername,
  46.             'error' => $error,
  47.             'csrf_token' => $csrfToken,
  48.         ]);
  49.     }
  50.     public function checkAction()
  51.     {
  52.         throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
  53.     }
  54.     public function logoutAction()
  55.     {
  56.         throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
  57.     }
  58.     /**
  59.      * Renders the login template with the given parameters. Overwrite this function in
  60.      * an extended controller to provide additional data for the login template.
  61.      *
  62.      * @return Response
  63.      */
  64.     protected function renderLogin(array $data)
  65.     {
  66.         
  67.         return $this->render('@FOSUser/Security/login.html.twig'$data);
  68.     }
  69. }