src/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\RoleRepository;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Exception;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. class SecurityController extends AbstractController
  12. {
  13.     #[Route('/login'name'login')]
  14.     public function login(AuthenticationUtils $authenticationUtils): Response
  15.     {
  16.         $error $authenticationUtils->getLastAuthenticationError();
  17.         $lastUsername $authenticationUtils->getLastUsername();
  18.         return $this->render('security/login.html.twig', [
  19.             'last_username' => $lastUsername,
  20.             'error' => $error,
  21.         ]);
  22.     }
  23.     /**
  24.      * @throws Exception
  25.      */
  26.     #[Route('/logout'name'logout')]
  27.     public function logout(): void
  28.     {
  29.         throw new Exception('Don\'t forget to activate logout in security.yaml');
  30.     }
  31.     #[Route('/add/user'name'addUser')]
  32.     public function addUser(EntityManagerInterface $entityManagerUserPasswordHasherInterface $userPasswordHasherRoleRepository $roleRepository)
  33.     {
  34. /*         $newUser = new User();
  35.          $newUser->setEmail('corentin.kistler@hotmail.com');
  36.          $newUser->setFirstName('Corentin');
  37.          $newUser->setLastName('KISTLER');
  38.         $newUser->setRoles(['ROLE_ADMIN']);
  39.         $newUser->setFullName($newUser->getFirstName() . ' ' . $newUser->getLastName());
  40.         $newUser->setPassword($userPasswordHasher->hashPassword(
  41.             $newUser,
  42.              '2909'
  43.          ));
  44.          $entityManager->persist($newUser);
  45.          $entityManager->flush();*/
  46.     }
  47. }