<?php
namespace App\Controller;
use App\Repository\RoleRepository;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route('/login', name: 'login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @throws Exception
*/
#[Route('/logout', name: 'logout')]
public function logout(): void
{
throw new Exception('Don\'t forget to activate logout in security.yaml');
}
#[Route('/add/user', name: 'addUser')]
public function addUser(EntityManagerInterface $entityManager, UserPasswordHasherInterface $userPasswordHasher, RoleRepository $roleRepository)
{
/* $newUser = new User();
$newUser->setEmail('corentin.kistler@hotmail.com');
$newUser->setFirstName('Corentin');
$newUser->setLastName('KISTLER');
$newUser->setRoles(['ROLE_ADMIN']);
$newUser->setFullName($newUser->getFirstName() . ' ' . $newUser->getLastName());
$newUser->setPassword($userPasswordHasher->hashPassword(
$newUser,
'2909'
));
$entityManager->persist($newUser);
$entityManager->flush();*/
}
}