domain-watchdog/src/Controller/HomeController.php

43 lines
1.2 KiB
PHP
Raw Normal View History

2024-07-19 02:28:05 +02:00
<?php
namespace App\Controller;
2024-07-22 02:17:42 +02:00
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
2024-07-19 02:28:05 +02:00
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2024-07-23 17:13:01 +02:00
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
2024-07-19 02:28:05 +02:00
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
2024-07-23 17:13:01 +02:00
use Symfony\Component\Routing\RouterInterface;
2024-07-19 02:28:05 +02:00
class HomeController extends AbstractController
{
2024-07-23 17:13:01 +02:00
public function __construct(private readonly RouterInterface $router)
{
}
2024-08-02 23:24:52 +02:00
#[Route(path: '/', name: 'index')]
2024-07-22 14:45:21 +02:00
public function index(): Response
{
return $this->render('base.html.twig');
}
2024-08-02 23:24:52 +02:00
#[Route(path: '/login/oauth', name: 'oauth_connect')]
2024-07-22 02:17:42 +02:00
public function connectAction(ClientRegistry $clientRegistry): Response
{
2024-08-03 00:06:38 +02:00
return $clientRegistry->getClient('oauth')->redirect([], []);
2024-07-22 02:17:42 +02:00
}
2024-07-23 17:13:01 +02:00
2024-08-02 23:24:52 +02:00
#[Route(path: '/logout', name: 'logout')]
2024-07-23 17:13:01 +02:00
public function logout(Security $security): ?RedirectResponse
{
$response = new RedirectResponse($this->router->generate('index'));
$response->headers->clearCookie('BEARER');
2024-08-02 23:24:52 +02:00
if ($security->isGranted('IS_AUTHENTICATED')) {
$security->logout(false);
}
2024-07-23 17:13:01 +02:00
return $response;
}
2024-07-22 13:39:45 +02:00
}