diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index d1a2e4707b4f9b020934623eb98861a0f981bced..2f90bb92e7070c47876bf413018207e8b8d6b06d 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -2,26 +2,39 @@ namespace App\Controller; +use App\Entity\Invitation; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use App\Entity\PurchaseProof; +use Doctrine\ORM\EntityManagerInterface; class HomeController extends AbstractController { #[Route('/', name: 'homepage')] - public function index(): Response + public function index(Request $request , EntityManagerInterface $entityManager): Response { - $joint_creation_URL = isset($_GET["joint_creation_URL"]) ? $_GET["joint_creation_URL"] : null; $user = $this->getUser(); // Récupère l'utilisateur connecté $links = [ ]; - if ($joint_creation_URL) { - $links["joint_creation_URL"] = $joint_creation_URL; + + $invitation_token = $request->getSession()->get("invitation_token"); + if($invitation_token){ + $invitation_id = InvitationController::verifyJointCreationToken($invitation_token); + + + if ($invitation_id) { + $user = $this->getUser(); + if ($user) { + $user->addInvitation($entityManager->find(Invitation::class, $invitation_id)); + $entityManager->persist($user); + $entityManager->flush(); + } + + } } // Ajoutez le lien "Admin Dashboard" uniquement si l'utilisateur est admin @@ -40,6 +53,7 @@ class HomeController extends AbstractController $links['Profile'] = $this->generateUrl('user_profile'); $links['Logout'] = $this->generateUrl('logout'); $links['See my purchase proofs'] = $this->generateUrl('user_purchase_proofs'); + $links['See my invitations'] = $this->generateUrl('app_invitation_index'); diff --git a/src/Controller/InvitationController.php b/src/Controller/InvitationController.php index c85534b08d9f266477509b996d49a5c1373ac97b..2120a274f8b70ef0eaf7df593c5064413c6a70ff 100644 --- a/src/Controller/InvitationController.php +++ b/src/Controller/InvitationController.php @@ -5,7 +5,6 @@ namespace App\Controller; use App\Entity\Invitation; use App\Entity\Wishlist; use App\Form\InvitationType; -use App\Repository\InvitationRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -17,10 +16,16 @@ use Symfony\Component\Routing\Attribute\Route; final class InvitationController extends AbstractController { #[Route(name: 'app_invitation_index', methods: ['GET'])] - public function index(InvitationRepository $invitationRepository): Response + public function index(): Response { + $user = $this->getUser(); + + if (!$user ) { + return $this->createAccessDeniedException("Vous devez être connecté pour accéder à cette page."); + } + return $this->render('invitation/index.html.twig', [ - 'invitations' => $invitationRepository->findAll(), + 'invitations' => $user->getInvitations(), ]); } @@ -96,11 +101,11 @@ final class InvitationController extends AbstractController $token = base64_encode($invitation_id . '|' . $hash); $serverIp = $_SERVER['SERVER_ADDR'] ?? '127.0.0.1'; - return sprintf('http://%s?invitation_token=%s', $serverIp, rtrim(strtr($token, '+/', '-_'), '=')); + return sprintf('http://%s/login?invitation_token=%s', $serverIp, rtrim(strtr($token, '+/', '-_'), '=')); } - private function verifyJointCreationToken(string $token): ?int { + public static function verifyJointCreationToken(string $token): ?int { $secretKey = 'top_secret_key_789/*-'; $token = strtr($token, '-_', '+/'); diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index af98a7890bd20a3874338b304a04450b892529d1..cd9606a623615513f0c59a9bbc8e7892aa1c007b 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -3,16 +3,22 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; -use Doctrine\ORM\EntityManagerInterface; class SecurityController extends AbstractController { #[Route('/login', name: 'login')] - public function login(AuthenticationUtils $authenticationUtils): Response + public function login(Request $request , AuthenticationUtils $authenticationUtils): Response { + + $invitation_token = $request->get('invitation_token'); + + if ($invitation_token) { + $request->getSession()->set('invitation_token',$invitation_token) ; + } // Récupère les erreurs de connexion, s'il y en a $error = $authenticationUtils->getLastAuthenticationError(); diff --git a/templates/invitation/index.html.twig b/templates/invitation/index.html.twig index b6d63b6fa238a3b8257914938b104dd67133383b..ecdf40990c6069d3aac40cda8ec57ba83ad0b616 100644 --- a/templates/invitation/index.html.twig +++ b/templates/invitation/index.html.twig @@ -1,33 +1,47 @@ {% extends 'base.html.twig' %} -{% block title %}Invitation index{% endblock %} +{% block title %}Wishlist Invitations{% endblock %} {% block body %} - <h1>Invitation index</h1> + <header> + <div class="user-icon"></div> + <h1><a href="#">Wishlist Invitations</a></h1> + <input type="text" class="search-bar" placeholder="Search..."> + <div style="margin-left: 10px; cursor: pointer;">☰</div> + </header> - <table class="table"> - <thead> - <tr> - <th>Id</th> - <th>actions</th> - </tr> - </thead> - <tbody> - {% for invitation in invitations %} - <tr> - <td>{{ invitation.id }}</td> - <td> - <a href="{{ path('app_invitation_show', {'id': invitation.id}) }}">show</a> - <a href="{{ path('app_invitation_edit', {'id': invitation.id}) }}">edit</a> - </td> - </tr> + <div class="container"> + {% if invitations|length > 0 %} + <div class="item-section"> + {% for invitation in invitations %} + <div class="wishlist"> + <h2> + <a href="{{ path('app_invitation_show', {'id': invitation.id}) }}"> + Wishlist {{ invitation.id }} + </a> + </h2> + <div class="wishlist-footer"> + <p>Inviter: {{ invitation.inviter.firstName ?? '' }} {{ invitation.inviter.lastName ?? 'Unavailable' }}</p> + <p>Email Inviter :{{invitation.inviter.email ?? 'Unavailable'}} </p> + </div> + <div class="wishlist-actions"> + <button title="Accept"><span>✔</span></button> + <button title="Delete"><span>🗑️</span></button> + </div> + <div class="wishlist-items"> + <div class="user-icon" style="width: 50px; height: 50px;"></div> + </div> + </div> + {% endfor %} + </div> {% else %} - <tr> - <td colspan="2">no records found</td> - </tr> - {% endfor %} - </tbody> - </table> + <p class="info-text">No invitations found.</p> + {% endif %} + </div> - <a href="{{ path('app_invitation_new') }}">Create new</a> -{% endblock %} + <div class="navbar"> + <button class="add-wishlist-btn"> + <a href="{{ path('app_invitation_new') }}" style="color: white; text-decoration: none;">Create new invitation</a> + </button> + </div> +{% endblock %} \ No newline at end of file