<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
// redirect to admin area if already logged in
return new RedirectResponse($this->generateUrl('easyadmin'));
}
return $this->render('admin/login.html.twig', [
'error' => $authenticationUtils->getLastAuthenticationError(),
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout(Request $request, Response $response, TokenInterface $token)
{
// Your custom logic here, for example:
$request->getSession()->getFlashBag()->add('notice', 'You have been logged out successfully.');
}
}