gestion de la connexion de l'utilisateur

This commit is contained in:
2026-03-18 17:34:21 +01:00
parent 3dcba06f20
commit d81e450a0e
19 changed files with 534 additions and 73 deletions

View File

@@ -2,38 +2,63 @@
namespace App\Controller;
use LogicException;
use App\Repository\UserRepository; // 👈 AJOUTE CETTE LIGNE ICI !
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; // 👈 ET CELLE-CI AUSSI !
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route(path: '/login', name: 'app_login', methods: ['GET','POST'])]
public function login(AuthenticationUtils $authenticationUtils): Response
#[Route(path: '/test-password', name: 'test_password')]
public function testPassword(UserRepository $userRepo, UserPasswordHasherInterface $hasher): Response
{
// 1. On va chercher ton admin directement en base
$admin = $userRepo->findOneBy(['email' => 'admin@kaz.fr']);
if (!$admin) {
dd("L'utilisateur n'existe pas dans la base lue par ce contrôleur !");
}
// 2. On vérifie si "password" est bien le bon mot de passe
$isValid = $hasher->isPasswordValid($admin, 'password');
// 3. On affiche le résultat brut
dd([
'email' => $admin->getEmail(),
'mot_de_passe_hache' => $admin->getPassword(),
'est_ce_que_password_est_valide' => $isValid
]);
}
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils, Request $request): Response // 👈 2. ON AJOUTE $request ICI
{
// 🚨 3. NOTRE CODE DE DÉTECTIVE POUR VOIR CE QUI EST ENVOYÉ :
if ($request->isMethod('POST')) {
dd($request->request->all());
}
// 🚨 FIN DU CODE DE DÉTECTIVE
// si on a un utilisateur déjà connecté, alors on le redirige sur la page d'accueil
if ($this->getUser()) {
return $this->redirectToRoute('app_home');
}
// get the login error if there is one
// Récupération de l'erreur de connexion (s'il y en a une)
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
// Récupération du dernier nom d'utilisateur saisi par l'adhérent
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'error' => $error
]);
}
#[Route(path: '/logout', name: 'app_logout', methods: ['POST'])]
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}
}