<?php
namespace App\Controller;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* This action serves the login Forms.
*
* @param AuthenticationUtils $authenticationUtils
*
* @Route("/login", name="login", methods={"GET", "POST"})
*
* @return Response
*/
public function login(AuthenticationUtils $authenticationUtils)
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* This action serves the Shibboleth route, which redirects to Shibboleth itself.
*
* @Route("/shibboleth", name="shibboleth", methods={"GET"})
*
* @return RedirectResponse
*/
public function shibbolethRedirectAction()
{
if (!$this->getUser()) {
return $this->redirect('index.php/shibboleth');
}
return $this->redirectToRoute('home');
}
/**
* Logout actions
*
* @Route("/logout", name="app_logout", methods={"GET"})
*
* @throws Exception
*/
public function logout()
{
// controller can be blank: it will never be executed!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}