src/UserIdentity/Infrastructure/Http/Controller/Web/SecurityController.php line 22

Open in your IDE?
  1. <?php
  2. namespace UserIdentity\Infrastructure\Http\Controller\Web;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Core\Security;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     public function __construct(
  12.         private Security $security)
  13.     {
  14.     }
  15.     /**
  16.      * @Route("/login", name="userIdentity.login")
  17.      */
  18.     public function loginAction(Request $requestAuthenticationUtils $authUtils): Response
  19.     {
  20.         if ($this->security->getUser() !== null) {
  21.             return $this->redirect($this->generateUrl('dashboard.main'));
  22.         }
  23.         // get the login error if there is one
  24.         $error $authUtils->getLastAuthenticationError();
  25.         // last username entered by the user
  26.         $lastUsername $authUtils->getLastUsername();
  27.         return $this->render('@UserIdentity/login.html.twig', [
  28.             'last_username' => $lastUsername,
  29.             'error' => $error,
  30.         ]);
  31.     }
  32.     /**
  33.      * @Route("/logout", name="userIdentity.logout")
  34.      */
  35.     public function logout(): void
  36.     {
  37.         // This method can be blank - it will be intercepted by the logout key in firewall.
  38.     }
  39. }