src/Controller/SecurityController.php line 24
<?phpnamespace App\Controller;use App\Entity\User;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Http\Attribute\CurrentUser;use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;use Symfony\Component\Security\Http\Util\TargetPathTrait;#[Route('/admin')]final class SecurityController extends AbstractController{use TargetPathTrait;/** The $user argument type (?User) must be nullable because the login page* must be accessible to anonymous visitors too.*/#[Route('/login', name: 'security_login')]public function login(#[CurrentUser] ?User $user,Request $request,AuthenticationUtils $helper,): Response {// if user is already logged in, don't display the login page againif ($user) {return $this->redirectToRoute('admin');}$this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin'));return $this->render('security/login.html.twig', [// last username entered by the user (if any)'last_username' => $helper->getLastUsername(),// last authentication error (if any)'error' => $helper->getLastAuthenticationError(),]);}/*** This is the route the user can use to logout.** But, this will never be executed. Symfony will intercept this first* and handle the logout automatically. See logout in config/packages/security.yaml*/#[Route('/logout', name: 'security_logout')]public function logout(): void{throw new \Exception('This should never be reached!');}}