<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route(path: '/user/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('home');
}
// 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]);
}
#[Route(path: '/counterparty/login', name: 'counterparty_login')]
public function counterpartyLogin(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('counterparty_home');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/counterparty_login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
#[Route(path: '/admin/auth/login', name: 'admin_login')]
public function adminLogin(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
if (in_array('ROLE_ADMIN', $this->getUser()->getRoles()) || in_array('ROLE_STAFF', $this->getUser()->getRoles())) {
return $this->redirectToRoute('admin_dashboard');
}
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/admin_login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
#[Route(path: '/user/logout', name: 'app_logout')]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
#[Route(path: '/counterparty/logout', name: 'counterparty_logout')]
public function counterpartyLogout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
#[Route(path: '/admin/logout', name: 'admin_logout')]
public function adminLogout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}