src/Controller/Admin/SecurityController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Config\Definition\Exception\Exception;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. /**
  10.  * Class SecurityController
  11.  * @package App\Controller\Admin
  12.  * @Route(path="/admin", name="admin_")
  13.  */
  14. class SecurityController extends AbstractController
  15. {
  16.     /**
  17.      * @param AuthenticationUtils $authenticationUtils
  18.      * @return Response
  19.      * @Route("/login", name="login")
  20.      */
  21.     public function login(AuthenticationUtils $authenticationUtils): Response
  22.     {
  23.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  24.             return $this->redirectToRoute('admin_index');
  25.         }
  26.         // get the login error if there is one
  27.         $error $authenticationUtils->getLastAuthenticationError();
  28.         // last username entered by the user
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         return $this->render('admin/security/login.html.twig', [
  31.             'last_username' => $lastUsername,
  32.             'error' => $error,
  33.         ]);
  34.     }
  35.     /**
  36.      * @throws Exception
  37.      * @Route("/logout", name="logout")
  38.      */
  39.     public function logout(): void
  40.     {
  41.         throw new Exception('This should never be reached!');
  42.     }
  43. }