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 8f83f71d53ef12cb9d70f22fe77bc8f7c5cb7069..3b99380de70e1e5d2765ef69d24c94c023e4f3e1 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 54e8db1deb65e42c651f4f04dbc8b8288a69efec..3f6757e13f54603fcee0fce0623c0a6ec7ab01cb 100644 --- a/templates/wishlist/index.html.twig +++ b/templates/wishlist/index.html.twig @@ -1,215 +1,36 @@ -{% extends 'base.html.twig' %} -{% block title %}My Wishlists{% endblock %} +{% extends 'base.html.twig' %} -{% block body %} -<header> - <div class="user-icon"></div> - <h1>My Wishlists</h1> - <input type="text" class="search-bar" placeholder="Search..."> -</header> +{% block title %} My Wishlists {% endblock %} -<div class="navbar"> - <button class="add-wishlist-btn" data-bs-toggle="modal" data-bs-target="#createWishlistModal">Add wishlist</button> -</div> -<!-- Create Wishlist Modal --> -<div class="modal fade" id="createWishlistModal" tabindex="-1" aria-labelledby="createWishlistModalLabel" aria-hidden="true"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <h5 class="modal-title" id="createWishlistModalLabel">Create New Wishlist</h5> - <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> - </div> - <div class="modal-body"> - <form id="createWishlistForm"> - <div class="mb-3"> - <label for="wishlistName" class="form-label">Name*</label> - <input type="text" class="form-control" id="wishlistName" required> - </div> - <div class="mb-3"> - <label for="wishlistDeadline" class="form-label">Deadline</label> - <input type="datetime-local" class="form-control" id="wishlistDeadline"> - </div> - <div class="mb-3 form-check"> - <input type="checkbox" class="form-check-input" id="wishlistIsDisabled"> - <label class="form-check-label" for="wishlistIsDisabled">Disabled</label> - </div> - </form> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> - <button type="button" class="btn btn-primary" id="submitWishlist">Create</button> - </div> - </div> +{% block body %} + <header> + <div class="user-icon"></div> + <h1>My Wishlists</h1> + <input type="text" class="search-bar" placeholder="Search..."> + </header> + + <div class="navbar"> + <button class="add-wishlist-btn">Add wishlist</button> </div> -</div> - -<div class="container"> - {% for wishlist in wishlists %} - <div class="wishlist {% if wishlist.isDisabled %}wishlist-disabled{% endif %}"> - <div class="wishlist-header"> - <h2>{{ wishlist.name }}</h2> - {% if wishlist.deadline %} - <span class="deadline-badge"> - Due: {{ wishlist.deadline|date('Y-m-d H:i') }} - {% if wishlist.deadline|date('U') < 'now'|date('U') %} - <span class="deadline-passed">(Passed)</span> - {% endif %} - </span> - {% endif %} - {% if wishlist.isDisabled %} - <span class="disabled-badge">Disabled</span> - {% endif %} - </div> - <div class="wishlist-items"> + + <div class="container"> + {% for wishlist in wishlists %} + <div class="wishlist"> + <h2>{{ wishlist.title }}</h2> + <div class="wishlist-items"> {% for item in wishlist.items %} <div class="wishlist-item">📷</div> {% endfor %} + </div> + <p class="wishlist-footer">Authors: name1, name2</p> + <div class="wishlist-actions"> + <button title="Share wishlist">↗</button> + <button title="Edit title">✏</button> + <button title="Delete wishlist">🗑</button> + </div> </div> - <p class="wishlist-footer">Authors: name1, name2</p> - <div class="wishlist-actions"> - <button title="Share wishlist">↗</button> - <button title="Edit wishlist">✏</button> - <button title="Delete wishlist">🗑</button> - </div> + {% end for %} </div> - {% endfor %} -</div> -{% endblock %} - -{% block javascripts %} -{{ parent() }} -<script> -document.addEventListener('DOMContentLoaded', function() { - document.getElementById('submitWishlist').addEventListener('click', function() { - const name = document.getElementById('wishlistName').value; - const deadline = document.getElementById('wishlistDeadline').value; - const isDisabled = document.getElementById('wishlistIsDisabled').checked; - - if (!name) { - alert('Please enter a name for your wishlist'); - return; - } - - fetch('/wishlists/create', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-Requested-With': 'XMLHttpRequest' - }, - body: JSON.stringify({ - name: name, - deadline: deadline, - isDisabled: isDisabled - }) - }) - .then(response => response.json()) - .then(data => { - if (data.success) { - bootstrap.Modal.getInstance(document.getElementById('createWishlistModal')).hide(); - window.location.reload(); - } else { - alert('Error creating wishlist: ' + data.message); - } - }) - .catch(error => { - console.error('Error:', error); - alert('An error occurred while creating the wishlist'); - }); - }); -}); -</script> -{% endblock %} - -{% block stylesheets %} -{{ parent() }} -<style> - .wishlist { - border: 1px solid #ddd; - border-radius: 8px; - padding: 15px; - margin-bottom: 20px; - box-shadow: 0 2px 4px rgba(0,0,0,0.1); - position: relative; - } - - .wishlist-disabled { - opacity: 0.7; - background-color: #f8f9fa; - } - - .wishlist-header { - display: flex; - justify-content: space-between; - align-items: center; - flex-wrap: wrap; - gap: 10px; - margin-bottom: 10px; - } - - .deadline-badge { - background: #e9ecef; - padding: 3px 8px; - border-radius: 4px; - font-size: 0.9em; - } - - .deadline-passed { - color: #dc3545; - font-weight: bold; - } - - .disabled-badge { - background: #6c757d; - color: white; - padding: 3px 8px; - border-radius: 4px; - font-size: 0.9em; - } - - .wishlist-items { - display: flex; - flex-wrap: wrap; - gap: 10px; - margin: 15px 0; - } - - .wishlist-item { - width: 60px; - height: 60px; - background: #f5f5f5; - border-radius: 4px; - display: flex; - align-items: center; - justify-content: center; - font-size: 24px; - } - - .wishlist-actions { - display: flex; - gap: 10px; - justify-content: flex-end; - } - - .wishlist-actions button { - background: none; - border: none; - cursor: pointer; - font-size: 18px; - } - - .add-wishlist-btn { - background-color: #4CAF50; - color: white; - border: none; - padding: 10px 15px; - border-radius: 4px; - cursor: pointer; - } - - .add-wishlist-btn:hover { - background-color: #45a049; - } -</style> -{% endblock %} \ No newline at end of file + {% endblock %}