src/Controller/SecurityController.php line 20
<?phpnamespace App\Controller;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;#[Route("/admin")]class SecurityController extends AbstractController{#[Route("/login", name: "login", methods: ["GET","POST"])]/*** @param Request $request* @param AuthenticationUtils $authenticationUtils* @param AuthorizationCheckerInterface $authorizationChecker* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response*/public function login(Request $request, AuthenticationUtils $authenticationUtils, AuthorizationCheckerInterface $authorizationChecker){// si déjà connecté on redirige sur la homeif ($request->getMethod() == 'GET' && $authorizationChecker->isGranted('ROLE_ADMIN')) {return $this->redirectToRoute('sonata_admin_dashboard');}// c'est un peu magique... mais ça marche// get the login error if there is one$error = $authenticationUtils->getLastAuthenticationError();// last username entered by the user$lastUsername = $authenticationUtils->getLastUsername();return $this->render('security/login.html.twig', ['last_username' => $lastUsername,'error' => $error,]);}#[Route("/logout", name: "logout")]public function logout(){// configuré dans config/packages/security.yaml}}