src/Controller/Security/SecurityController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Security;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Entity\User;
  7. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/security/create-user", name="create_user")
  13.      */
  14.     public function create(UserPasswordHasherInterface $passwordHasher): Response
  15.     {
  16.         return $this->render('views/pages/security/create_user/index.html.twig', [
  17.             'controller_name' => 'SecurityController',
  18.         ]);
  19.     }
  20.     
  21.     /**
  22.      * @Route("/security/login", name="login")
  23.      */
  24.     public function login(AuthenticationUtils $authenticationUtils): Response
  25.     {
  26.         // get the login error if there is one
  27.         $error $authenticationUtils->getLastAuthenticationError();
  28.         // last username entered by the user
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         return $this->render('views/pages/security/login/index.html.twig', ['last_username' => $lastUsername'error' => $error]);
  31.     }
  32.     
  33.     /**
  34.      * @Route("/security/logout", name="app_logout", methods={"GET"})
  35.      */
  36.     public function logout(): void
  37.     {
  38.         // controller can be blank: it will never be called!
  39.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  40.     }
  41. }