<?php
namespace App\Controller;
use RuntimeException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route('/login', name: 'app_login')]
#[Template]
public function login(AuthenticationUtils $authenticationUtils): array
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return [
'last_username' => $lastUsername,
'error' => $error,
];
}
/**
* @throws RuntimeException
*/
#[Route('/logout', name: 'app_logout', methods: ['GET'])]
public function logout(): void
{
// controller can be blank: it will never be called!
throw new RuntimeException('Don\'t forget to activate logout in security.yaml');
}
}