src/Controller/SecurityController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Exception;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     /**
  12.      * This action serves the login Forms.
  13.      *
  14.      * @param AuthenticationUtils $authenticationUtils
  15.      *
  16.      * @Route("/login", name="login", methods={"GET", "POST"})
  17.      *
  18.      * @return Response
  19.      */
  20.     public function login(AuthenticationUtils $authenticationUtils)
  21.     {
  22.         // get the login error if there is one
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         // last username entered by the user
  25.         $lastUsername $authenticationUtils->getLastUsername();
  26.         return $this->render('security/login.html.twig', [
  27.             'last_username' => $lastUsername,
  28.             'error' => $error,
  29.         ]);
  30.     }
  31.     /**
  32.      * This action serves the Shibboleth route, which redirects to Shibboleth itself.
  33.      *
  34.      * @Route("/shibboleth", name="shibboleth", methods={"GET"})
  35.      *
  36.      * @return RedirectResponse
  37.      */
  38.     public function shibbolethRedirectAction()
  39.     {
  40.         if (!$this->getUser()) {
  41.             return $this->redirect('index.php/shibboleth');
  42.         }
  43.         return $this->redirectToRoute('home');
  44.     }
  45.     /**
  46.      * Logout actions
  47.      *
  48.      * @Route("/logout", name="app_logout", methods={"GET"})
  49.      *
  50.      * @throws Exception
  51.      */
  52.     public function logout()
  53.     {
  54.         // controller can be blank: it will never be executed!
  55.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  56.     }
  57. }