diff --git a/src/Controller/ModifUserController.php b/src/Controller/ModifUserController.php index af8fbfa6c76c87d2140d40777d0b5e9bb9ddbf88..4dcd861a7812a833ca6f66fbb0a80d4cee064b3f 100644 --- a/src/Controller/ModifUserController.php +++ b/src/Controller/ModifUserController.php @@ -8,6 +8,7 @@ use App\Entity\Administrateur; use App\Entity\Pret; use App\Entity\Services; use App\Form\ModifUserCoordFormType; +use App\Form\ModifUserAbonnementFormType; use App\Form\ModifPasswordType; use App\Form\CompteSommeilFormType; use App\Repository\PrestationsRepository; @@ -20,6 +21,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Form\FormError; +use Symfony\Component\HttpFoundation\JsonResponse; class ModifUserController extends AbstractController { @@ -221,4 +223,36 @@ class ModifUserController extends AbstractController 'user' => $user, ]); } + + #[Route('/modifUserAbonnement', name: 'app_modif_user_abonnement')] + public function modifUserAbonnement(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response + { + $user = $this->getUser(); + + return $this->render('security/modifUserAbonnement.html.twig', [ + 'user' => $user, + ]); + } + + #[Route('/ameliorerAbonnement', name: 'app_ameliorer_abonnement')] + public function ameliorer(EntityManagerInterface $entityManager): JsonResponse + { + $user = $this->getUser(); + $user->setStatusAbonnement(1); + $entityManager->flush(); + + return new JsonResponse(['success' => true]); + } + + #[Route('/retrograderAbonnement', name: 'app_retrograder_abonnement')] + public function retrograder(EntityManagerInterface $entityManager): JsonResponse + { + $user = $this->getUser(); + $user->setStatusAbonnement(0); + $nbFlorains = $user->getNbFlorains(); + $user->setNbFlorains($nbFlorains + 500); + $entityManager->flush(); + + return new JsonResponse(['success' => true]); + } } diff --git a/templates/header.html.twig b/templates/header.html.twig index d9a0afeef7b7ab3d75a7e2ba66a8ca01c8326ca5..e4ea51503637c809ea90da6a929ab17ee1d767cf 100644 --- a/templates/header.html.twig +++ b/templates/header.html.twig @@ -11,6 +11,9 @@ <p>{{ app.user.login }}</p> <a href="{{ path("app_notifications")}}"><img src={{asset('/img/notifs.png')}} alt="logo profil" width="35px"/></a> <a href="{{ path("app_modif_user")}}" ><img src={{asset('/img/bonhomme.png')}} alt="logo profil" width="50px"/></a> + {% if not is_granted('ROLE_ADMIN') %} + <p>Solde: {{ app.user.getNbFlorains() }}</p> + {% endif %} {% else %} <div> <a href="{{ path("app_login")}}"><button class="creation_annonce">Publier une annonce</button></a> diff --git a/templates/security/mes_annonces.html.twig b/templates/security/mes_annonces.html.twig index fee9ae6e407a0eafe445443fd9f4c6de927a09b9..3f88c3120c061ba2c0f607a5f60137b8110aac26 100644 --- a/templates/security/mes_annonces.html.twig +++ b/templates/security/mes_annonces.html.twig @@ -8,9 +8,6 @@ .example-wrapper code { padding: 2px 6px; } .footer { margin: 15px; position: absolute; bottom: 0; } </style> - -<h1>Mes annonces</h1> - <div class="container-recherche"> <form id="filterForm" method="post"> <input class="txt_form" type="text" name="keyword" value="{{ app.request.query.get('keyword') }}" placeholder="Mot-clé"> diff --git a/templates/security/modifUser.html.twig b/templates/security/modifUser.html.twig index cf8080bcb1704c8526a710d467f3baaf3417f3e5..d485e88d69369d05c1fd13ad0ca31d376f7dd34f 100644 --- a/templates/security/modifUser.html.twig +++ b/templates/security/modifUser.html.twig @@ -19,7 +19,7 @@ <button class="btn-connexion2" onclick="window.location.href='{{ path("app_user_coord") }}'">Mon profil</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_mes_annonces") }}'">Consulter mes transactions</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_coord") }}'">Modifier mes coordonnées</button> - <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_coord") }}'">Modifier mon abonnement</button> + <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_abonnement") }}'">Modifier mon abonnement</button> <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user_mdp") }}'">Modifier mon mot de passe</button> {% if app.user.isSommeil()%} diff --git a/templates/security/modifUserAbonnement.html.twig b/templates/security/modifUserAbonnement.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..e2d258bfd6209bbf9b0f8cd1007d61ca439b063d --- /dev/null +++ b/templates/security/modifUserAbonnement.html.twig @@ -0,0 +1,49 @@ +{% extends 'base.html.twig' %} + +{% block title %}Modif abonnement{% endblock %} + +{% block body %} +<div class="container-connexion3"> + <div class="container-connexion"> + <div class="container-connexion2"> + <h1>Mon abonnement</h1> + {% if user.statusabonnement == 0 %} + <p><strong>Statut abonnement:</strong> Abonnement standard</p> + <p>Passez à un abonnement premium pour 10€</p> + <button type="button" class="btn-connexion" onclick="ameliorer()">Modifier mon abonnement (-10€)</button> + {% else %} + <p><strong>Statut abonnement:</strong> Abonnement premium</p> + <p>Rétrogradez à un abonnement standard et obtenez 500 florains </p> + <button type="button" class="btn-connexion" onclick="retrograder()">Modifier mon abonnement (+500 florains)</button> + {% endif %} + </div> + <button class="btn-connexion2" onclick="window.location.href='{{ path("app_modif_user") }}'">Retour</button> + </div> +</div> + +<script> + function ameliorer() { + fetch('{{ path("app_ameliorer_abonnement") }}', { method: 'POST' }) + .then(response => { + if (response.ok) { + window.location.reload(); + } else { + console.error('Échec de la mise à niveau de l\'abonnement'); + } + }) + .catch(error => console.error('Erreur :', error)); + } + + function retrograder() { + fetch('{{ path("app_retrograder_abonnement") }}', { method: 'POST' }) + .then(response => { + if (response.ok) { + window.location.reload(); + } else { + console.error('Échec de la rétrogradation de l\'abonnement'); + } + }) + .catch(error => console.error('Erreur :', error)); + } +</script> +{% endblock %}