diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 1281e9d..9232d38 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -4,12 +4,19 @@ namespace App\Controller; use KnpU\OAuth2ClientBundle\Client\ClientRegistry; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Routing\RouterInterface; class HomeController extends AbstractController { + public function __construct(private readonly RouterInterface $router) + { + } + #[Route(path: "/", name: "index")] public function index(): Response { @@ -21,4 +28,14 @@ class HomeController extends AbstractController { return $clientRegistry->getClient('oauth')->redirect(); } + + #[Route(path: "/logout", name: "logout")] + public function logout(Security $security): ?RedirectResponse + { + $response = new RedirectResponse($this->router->generate('index')); + $response->headers->clearCookie('BEARER'); + if ($security->isGranted('IS_AUTHENTICATED')) $security->logout(false); + + return $response; + } } diff --git a/src/Entity/Domain.php b/src/Entity/Domain.php index 3b07462..e03501e 100644 --- a/src/Entity/Domain.php +++ b/src/Entity/Domain.php @@ -5,7 +5,6 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Metadata\Post; use App\Controller\DomainRefreshController; use App\Repository\DomainRepository; use DateTimeImmutable; @@ -13,7 +12,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Serializer\Attribute\Groups; use Symfony\Component\Serializer\Attribute\SerializedName;