src/Controller/SecurityController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. class SecurityController extends AbstractController
  8. {
  9.     #[Route(path'/user/login'name'app_login')]
  10.     public function login(AuthenticationUtils $authenticationUtils): Response
  11.     {
  12.         if ($this->getUser()) {
  13.             return $this->redirectToRoute('home');
  14.         }
  15.         // get the login error if there is one
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         // last username entered by the user
  18.         $lastUsername $authenticationUtils->getLastUsername();
  19.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  20.     }
  21.     #[Route(path'/counterparty/login'name'counterparty_login')]
  22.     public function counterpartyLogin(AuthenticationUtils $authenticationUtils): Response
  23.     {
  24.         if ($this->getUser()) {
  25.             return $this->redirectToRoute('counterparty_home');
  26.         }
  27.         // get the login error if there is one
  28.         $error $authenticationUtils->getLastAuthenticationError();
  29.         // last username entered by the user
  30.         $lastUsername $authenticationUtils->getLastUsername();
  31.         return $this->render('security/counterparty_login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  32.     }
  33.     #[Route(path'/admin/auth/login'name'admin_login')]
  34.     public function adminLogin(AuthenticationUtils $authenticationUtils): Response
  35.     {
  36.         if ($this->getUser()) {
  37.             if (in_array('ROLE_ADMIN'$this->getUser()->getRoles()) || in_array('ROLE_STAFF'$this->getUser()->getRoles())) {
  38.                 return $this->redirectToRoute('admin_dashboard');
  39.             }
  40.         }
  41.         // get the login error if there is one
  42.         $error $authenticationUtils->getLastAuthenticationError();
  43.         // last username entered by the user
  44.         $lastUsername $authenticationUtils->getLastUsername();
  45.         return $this->render('security/admin_login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  46.     }
  47.     #[Route(path'/user/logout'name'app_logout')]
  48.     public function logout(): void
  49.     {
  50.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  51.     }
  52.     #[Route(path'/counterparty/logout'name'counterparty_logout')]
  53.     public function counterpartyLogout(): void
  54.     {
  55.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  56.     }
  57.     #[Route(path'/admin/logout'name'admin_logout')]
  58.     public function adminLogout(): void
  59.     {
  60.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  61.     }
  62. }