<?php
namespace App\Controller;
use App\Repository\UserRepository;
use Doctrine\Persistence\ManagerRegistry;
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 SecurityController extends AbstractController
{
/**
* @Route("/", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils, ManagerRegistry $doctrine): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$name = '';
if ($lastUsername)
{
$userRepo = new UserRepository($doctrine);
if ($currentUser = $userRepo->getByLogin($lastUsername)) {
$name = $currentUser->getName();
}
}
return $this->render('security/login.html.twig', ['last_username' => $name, 'error' => $error]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}
}