diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 0f5af18..a8f9810 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,7 +1,7 @@ security: # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords password_hashers: - Symfony\Component\Security\Core\Employee: 'auto' + Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider providers: # used to reload user from session & other features (e.g. switch_user) @@ -40,7 +40,7 @@ security: # Easy way to control access for large sections of your site # Note: Only the *first* access control that matches will be used access_control: - #- { path: ^/*, roles: ROLE_USER } + - { path: ^/*, roles: ROLE_USER } when@test: security: diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index 594ec91..bba229c 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -9,7 +9,7 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; class DashboardController extends AbstractController { - #[Route(path: '/dashboard', name: 'app_dashboard')] + #[Route(path: '/dashboard', name: 'dashboard')] public function index(): Response { return $this->render('dashboard/index.html.twig'); diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 664f476..4e4de2f 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -2,7 +2,9 @@ namespace App\Controller; +use App\Form\LoginType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; @@ -13,12 +15,13 @@ class SecurityController extends AbstractController #[Route(path: '', name: '_login')] public function login(AuthenticationUtils $authenticationUtils): Response { - // if ($this->getUser()) { - // return $this->redirectToRoute('target_path'); - // } +// if ($this->getUser()) { +// return $this->redirectToRoute('dashboard'); +// } // get the login error if there is one $error = $authenticationUtils->getLastAuthenticationError(); + // last username entered by the user $lastUsername = $authenticationUtils->getLastUsername(); @@ -26,7 +29,7 @@ class SecurityController extends AbstractController return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); } - #[Route(path: '/logout', name: 'app_logout')] + #[Route(path: '/logout', name: '_logout')] public function logout(): void { throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); diff --git a/src/Entity/MissionCategory.php b/src/Entity/MissionCategory.php index 862d5a8..3081dc2 100644 --- a/src/Entity/MissionCategory.php +++ b/src/Entity/MissionCategory.php @@ -6,16 +6,17 @@ use App\Repository\MissionCategoryRepository; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: MissionCategoryRepository::class)] +#[ORM\UniqueConstraint(columns: ['mission', 'category'])] class MissionCategory { #[ORM\Id] - #[ORM\OneToMany(targetEntity: Mission::class, mappedBy: 'MissionCategory')] - #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(targetEntity: Mission::class, inversedBy: 'missionCategories')] + #[ORM\Column(type: 'integer')] private ?Mission $mission = null; #[ORM\Id] - #[ORM\OneToMany(targetEntity: Category::class, mappedBy: 'MissionCategory')] - #[ORM\JoinColumn(nullable: false)] + #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: 'missionCategories')] + #[ORM\Column(type: 'integer')] private ?Category $category = null; public function getMission(): ?Mission diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index 1d26146..1ea3330 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -20,7 +20,7 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator { use TargetPathTrait; - public const LOGIN_ROUTE = 'app_login'; + public const LOGIN_ROUTE = 'security_login'; public function __construct(private UrlGeneratorInterface $urlGenerator) { @@ -28,13 +28,13 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator public function authenticate(Request $request): Passport { - $email = $request->getPayload()->getString('email'); + $email = $request->getPayload()->getString('_username'); $request->getSession()->set(SecurityRequestAttributes::LAST_USERNAME, $email); return new Passport( new UserBadge($email), - new PasswordCredentials($request->getPayload()->getString('password')), + new PasswordCredentials($request->getPayload()->getString('_password')), [ new CsrfTokenBadge('authenticate', $request->getPayload()->getString('_csrf_token')), new RememberMeBadge(), @@ -44,12 +44,12 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { - if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) { + /*if ($targetPath = $this->getTargetPath($request->getSession(), $firewallName)) { return new RedirectResponse($targetPath); - } + }*/ // For example: - return new RedirectResponse($this->urlGenerator->generate('app_dashboard')); + return new RedirectResponse($this->urlGenerator->generate('dashboard')); //return new RedirectResponse($this->urlGenerator->generate('DashboardController')); } diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index 89379d3..5b22657 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -3,23 +3,39 @@ {% block title %}HegreLand{% endblock %} {% block body %} -