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

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\Controller;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\Session\Session;
  15. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  16. use Symfony\Component\Security\Core\Security;
  17. class SecurityController extends Controller
  18. {
  19.     /**
  20.      * @param Request $request
  21.      *
  22.      * @return Response
  23.      */
  24.     public function loginAction(Request $request)
  25.     {
  26.         /** @var $session Session */
  27.         $session $request->getSession();
  28.         $authErrorKey Security::AUTHENTICATION_ERROR;
  29.         $lastUsernameKey Security::LAST_USERNAME;
  30.         // get the error if any (works with forward and redirect -- see below)
  31.         if ($request->attributes->has($authErrorKey)) {
  32.             $error $request->attributes->get($authErrorKey);
  33.         } elseif (null !== $session && $session->has($authErrorKey)) {
  34.             $error $session->get($authErrorKey);
  35.             $session->remove($authErrorKey);
  36.         } else {
  37.             $error null;
  38.         }
  39.         if (!$error instanceof AuthenticationException) {
  40.             $error null// The value does not come from the security component.
  41.         }
  42.         // last username entered by the user
  43.         $lastUsername = (null === $session) ? '' $session->get($lastUsernameKey);
  44.         $csrfToken $this->has('security.csrf.token_manager')
  45.             ? $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue()
  46.             : null;
  47.         return $this->renderLogin(array(
  48.             'last_username' => $lastUsername,
  49.             'error' => $error,
  50.             'csrf_token' => $csrfToken,
  51.         ));
  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.      * @param array $data
  58.      *
  59.      * @return Response
  60.      */
  61.     protected function renderLogin(array $data)
  62.     {
  63.         return $this->render('@FOSUser/Security/login.html.twig'$data);
  64.     }
  65.     public function checkAction()
  66.     {
  67.         throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
  68.     }
  69.     public function logoutAction()
  70.     {
  71.         throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
  72.     }
  73. }