From 5910c32002f488ca7cfdd863ce3a7cb8eeda6bd3 Mon Sep 17 00:00:00 2001 From: user <user@imta.fr> Date: Tue, 25 Mar 2025 22:19:04 +0100 Subject: [PATCH] User V4 --- config/packages/security.yaml | 6 +++--- src/Controller/HomeController.php | 23 +++++++++++++++++++++++ src/Controller/RegistrationController.php | 2 +- src/Controller/UserController.php | 2 ++ src/Entity/User.php | 13 +++++++------ templates/home/index.html.twig | 15 +++++++++++++++ templates/wishlist/index.html.twig | 4 ++-- 7 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 src/Controller/HomeController.php create mode 100644 templates/home/index.html.twig diff --git a/config/packages/security.yaml b/config/packages/security.yaml index c1cc3ab4..b9d10f0e 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 00000000..6a27413e --- /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 fbf5028d..46f72b78 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 b058aa94..a53eb97e 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 197c8767..cdda1070 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 00000000..c5465809 --- /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 685f80f9..f08571c4 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 %} -- GitLab