src/Controller/bundles/FOSUserBundle/SecurityController.php line 96

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 App\Controller\bundles\FOSUserBundle;
  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. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  18. /**
  19.  * Controller managing security.
  20.  *
  21.  * @author Thibault Duplessis <thibault.duplessis@gmail.com>
  22.  * @author Christophe Coevoet <stof@notk.org>
  23.  */
  24. class SecurityController extends Controller {
  25.     private $tokenManager;
  26.     public function __construct(CsrfTokenManagerInterface $tokenManager null) {
  27.         $this->tokenManager $tokenManager;
  28.     }
  29.     /**
  30.      * @param Request $request
  31.      *
  32.      * @return Response
  33.      */
  34.     public function loginAction(Request $request) {
  35.         if ($this->isGranted("IS_AUTHENTICATED_REMEMBERED")) {
  36.             return $this->redirectToRoute("dashboard_index");
  37.         }
  38.         /** @var $session Session */
  39.         $session $request->getSession();
  40.         $authErrorKey Security::AUTHENTICATION_ERROR;
  41.         $lastUsernameKey Security::LAST_USERNAME;
  42.         // get the error if any (works with forward and redirect -- see below)
  43.         if ($request->attributes->has($authErrorKey)) {
  44.             $error $request->attributes->get($authErrorKey);
  45.         } elseif (null !== $session && $session->has($authErrorKey)) {
  46.             $error $session->get($authErrorKey);
  47.             $session->remove($authErrorKey);
  48.         } else {
  49.             $error null;
  50.         }
  51.         if (!$error instanceof AuthenticationException) {
  52.             $error null// The value does not come from the security component.
  53.         }
  54.         // last username entered by the user
  55.         $lastUsername = (null === $session) ? '' $session->get($lastUsernameKey);
  56.         $csrfToken $this->tokenManager $this->tokenManager->getToken('authenticate')->getValue() : null;
  57.         return $this->renderLogin(array(
  58.                     'last_username' => $lastUsername,
  59.                     'error' => $error,
  60.                     'csrf_token' => $csrfToken,
  61.         ));
  62.     }
  63.     public function checkAction() {
  64.         throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
  65.     }
  66.     public function logoutAction() {
  67.         throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
  68.     }
  69.     /**
  70.      * Renders the login template with the given parameters. Overwrite this function in
  71.      * an extended controller to provide additional data for the login template.
  72.      *
  73.      * @param array $data
  74.      *
  75.      * @return Response
  76.      */
  77.     protected function renderLogin(array $data) {
  78.         // return $this->render('@FOSUser/Security/login.html.twig', $data);
  79.         return $this->render('Front/Luminous/signin.html.twig'$data);
  80.     }
  81. }