1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php
namespace JC\BourseBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
class SecurityController extends Controller
{
/**
* @Route("/login", name="_login")
*
*/
public function loginAction()
{
// ON récupère les erreurs d'authentification si le formulaire a été passé avec de mauvaises informations
if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->render('JCBourseBundle:Default:login.html.twig', array(
// On envoie à notre vue le login qu'a saisi l'utilisateur précédemment
'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
// Et les erreurs qu'il y a eut lors de la validation du formulaire
'error' => $error,
));
}
/**
* @Route("/logout", name="_security_logout")
*
*/
public function logoutAction()
{
/*
$session = $this->getRequest()->getSession();
$token = $session->get('token');
$this->get("request")->getSession()->invalidate();
$this->get("security.context")->setToken(null);
$this->getRequest()->getSession()->remove('token');
*/
return $this->redirect($this->generateUrl('_login', array()));
}
} |