<?php
declare(strict_types=1);
namespace Smakmedia\Controller;
use Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
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 LoginController extends AbstractController
{
/**
* @Route("/login", name="login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->isGranted('ROLE_USER')) {
return $this->redirectToRoute('dashboard');
}
$error = $authenticationUtils->getLastAuthenticationError();
$username = $authenticationUtils->getLastUsername();
return $this->render('login.html.twig', [
'username' => $username,
'error' => $error,
]);
}
/**
* @IsGranted("ROLE_USER")
*
* @Route("/logout", name="logout", methods={"GET"})
*/
public function logout()
{
// controller can be blank: it will never be executed!
throw new Exception('Don\'t forget to activate logout in security.yaml');
}
}