src/Controller/SecurityController.php line 17
<?php
namespace App\Controller;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
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(path: '/', name: 'app_start')]
public function start(): Response
{
return $this->redirectToRoute('app_login');
}
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app_admin');
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUserName = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUserName, 'error' => $error]);
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new \LogicException('This method should never be reached');
}
// #[Route(path: '/user/new', name: 'app_new_user')]
// public function createUser(UserPasswordHasherInterface $hasher, EntityManagerInterface $entityManager): JsonResponse
// {
// $user = new User();
// $user->setUsername("");
// $user->setPassword($hasher->hashPassword($user, ""));
// $entityManager->persist($user);
//
// $entityManager->flush();
// return new JsonResponse(["Done"]);
// }
}