diff --git a/config/packages/security.yaml b/config/packages/security.yaml index c1cc3ab486014f1f933d5b65f9e8ec7b4f14a6bf..b9d10f0e8672c8d08d54e58a61cde918c3875818 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -24,9 +24,9 @@ security: remember_me: secret: '%kernel.secret%' - # access_control: - # - { path: ^/admin, allow_if: "user and user.isAdmin == true" } - # - { path: ^/locked, allow_if: "user and user.isLocked == true" } + access_control: + - { path: ^/admin, allow_if: "user and user.isAdmin == true" } + #- { path: ^/user, allow_if: "user and user.isLocked == false" } when@test: security: diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php new file mode 100644 index 0000000000000000000000000000000000000000..6a27413e245f8a2b400aff981fdd99ee158e27e9 --- /dev/null +++ b/src/Controller/HomeController.php @@ -0,0 +1,23 @@ +<?php + +namespace App\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; + +class HomeController extends AbstractController +{ + #[Route('/', name: 'homepage')] + public function index(): Response + { + return $this->render('home/index.html.twig', [ + 'links' => [ + 'Register' => $this->generateUrl('register'), + 'Login' => $this->generateUrl('login'), + 'My Wishlists' => $this->generateUrl('app_wishlist_index'), + 'Admin Dashboard' => $this->generateUrl('admin_dashboard'), + ], + ]); + } +} \ No newline at end of file diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index fbf5028dc649bb727b6452e82a533df8d11bd6ad..46f72b7833b2f63c6981725a44e6c4017a8d6d27 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -22,7 +22,7 @@ class RegistrationController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { // Hacher le mot de passe - $hashedPassword = $passwordHasher->hashPassword($user, $user->getPassword()); + $hashedPassword = $passwordHasher->hashPassword($user, $form->get('plainPassword')->getData()); $user->setPassword($hashedPassword); // Sauvegarder l'utilisateur diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index b058aa940aab4de75d2b82cd10a39f23e66d420c..a53eb97ea42b9538832991f6359a3350cc2125dc 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -6,6 +6,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; +use Symfony\Component\Security\Core\User\UserInterface; final class UserController extends AbstractController { diff --git a/src/Entity/User.php b/src/Entity/User.php index 197c87673a763194b5e52811967924622573e979..cdda1070d188ed0aa7c04e7faf7411790d2c0cba 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -5,11 +5,12 @@ namespace App\Entity; use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; #[ORM\Entity(repositoryClass: UserRepository::class)] -class User implements UserInterface +class User implements UserInterface, PasswordAuthenticatedUserInterface { private array $roles = []; @@ -34,7 +35,7 @@ class User implements UserInterface #[ORM\Column] private ?int $id = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255, unique: true)] private ?string $email = null; #[ORM\Column(length: 63)] @@ -46,11 +47,11 @@ class User implements UserInterface #[ORM\Column(length: 255)] private ?string $password = null; - #[ORM\Column] - private ?bool $isLocked = null; + #[ORM\Column(type: 'boolean', options: ['default' => false])] + private ?bool $isLocked = false; - #[ORM\Column] - private ?bool $isAdmin = null; + #[ORM\Column(type: 'boolean', options: ['default' => false])] + private ?bool $isAdmin = false; #[ORM\Column(length: 255, nullable: true)] private ?string $image = null; diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..c54658099b28dc9694277438e16e5df6408315ab --- /dev/null +++ b/templates/home/index.html.twig @@ -0,0 +1,15 @@ +{% extends 'base.html.twig' %} + +{% block title %}Homepage{% endblock %} + +{% block body %} +<div class="container mt-5"> + <h1>Welcome to the Wishlist Project</h1> + <p>Here are the main links to navigate through the project:</p> + <ul> + {% for label, url in links %} + <li><a href="{{ url }}">{{ label }}</a></li> + {% endfor %} + </ul> +</div> +{% endblock %} \ No newline at end of file diff --git a/templates/wishlist/index.html.twig b/templates/wishlist/index.html.twig index 685f80f953ac33933b95f196be365d8d9c0e3c50..f08571c4e46059f76d4f5d78d8fa32345f995300 100644 --- a/templates/wishlist/index.html.twig +++ b/templates/wishlist/index.html.twig @@ -16,7 +16,7 @@ </div> <div class="container"> - {% for wishlist in Wishlists %} + {% for wishlist in wishlists %} <div class="wishlist"> <h2>{{ wishlist.title }}</h2> <div class="wishlist-items"> @@ -31,6 +31,6 @@ <button title="Delete wishlist">🗑</button> </div> </div> - {% end for %} + {% endfor %} </div> {% endblock %}