src/Controller/SecurityController.php line 17

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  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(path'/'name'app_start')]
  14.     public function start(): Response
  15.     {
  16.         return $this->redirectToRoute('app_login');
  17.     }
  18.     #[Route(path'/login'name'app_login')]
  19.     public function login(AuthenticationUtils $authenticationUtils): Response
  20.     {
  21.         if ($this->getUser()) {
  22.             return $this->redirectToRoute('app_admin');
  23.         }
  24.         $error $authenticationUtils->getLastAuthenticationError();
  25.         $lastUserName $authenticationUtils->getLastUsername();
  26.         return $this->render('security/login.html.twig', ['last_username' => $lastUserName'error' => $error]);
  27.     }
  28.     #[Route(path'/logout'name'app_logout')]
  29.     public function logout(): void
  30.     {
  31.         throw new \LogicException('This method should never be reached');
  32.     }
  33. //    #[Route(path: '/user/new', name: 'app_new_user')]
  34. //    public function createUser(UserPasswordHasherInterface $hasher, EntityManagerInterface $entityManager): JsonResponse
  35. //    {
  36. //        $user = new User();
  37. //        $user->setUsername("");
  38. //        $user->setPassword($hasher->hashPassword($user, ""));
  39. //        $entityManager->persist($user);
  40. //
  41. //        $entityManager->flush();
  42. //        return new JsonResponse(["Done"]);
  43. //    }
  44. }