From da265c50bc8c85fa14aa9c331a30947e1837bcb7 Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Thu, 13 Jun 2024 08:48:25 +0200 Subject: [PATCH 1/5] Connection checking --- src/Controller/ProfilController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index 2d1b473..ee866b2 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -71,7 +71,6 @@ class ProfilController extends AbstractController }catch (\Exception $e){ return $this->redirectToRoute('app_login'); } - $profil = $this->mgr->find(Profil::class, $id); if ($profil instanceof Profil) { $profil->removeFollower($this->getUser()); From 81efb8aa973552766b13dabb077ad8e35ba3f2e4 Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Thu, 13 Jun 2024 09:01:22 +0200 Subject: [PATCH 2/5] Adding link to profil from post's pic --- public/css/components/post.css | 5 +++++ templates/post/post.html.twig | 6 ++++-- templates/post/post_mini.html.twig | 14 ++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/public/css/components/post.css b/public/css/components/post.css index 6f67aa8..af6f77e 100644 --- a/public/css/components/post.css +++ b/public/css/components/post.css @@ -32,4 +32,9 @@ p { hr { color: black; +} + +a { + text-decoration: none; + color: black; } \ No newline at end of file diff --git a/templates/post/post.html.twig b/templates/post/post.html.twig index 210868b..9ca843c 100644 --- a/templates/post/post.html.twig +++ b/templates/post/post.html.twig @@ -10,8 +10,10 @@
- - {{ post.profil.name }} + + + + {{ post.profil.name }} {# - {{ post.dateCreated }} #} - Il y a 3 jours
diff --git a/templates/post/post_mini.html.twig b/templates/post/post_mini.html.twig index b70ceb4..ca75a66 100644 --- a/templates/post/post_mini.html.twig +++ b/templates/post/post_mini.html.twig @@ -1,17 +1,19 @@ {% block body %} -
- - {{ post.profil.name }} + + + + {{ post.profil.name }} {# - {{ post.dateCreated }} #} - Il y a 3 jours
-

{{ post.title }}

-

{{ post.text|u.truncate(150, true, '...') }}

+ +

{{ post.title }}

+

{{ post.text|u.truncate(150, true, '...') }}

+
- {% endblock %} From 0f459a355b6ebc9765385d1e50cac4f8ce2c1dab Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Thu, 13 Jun 2024 09:07:36 +0200 Subject: [PATCH 3/5] Try catch removed --- src/Controller/ProfilController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index ee866b2..3d7d5c1 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -22,11 +22,7 @@ class ProfilController extends AbstractController #[Route(path: "/profil", name: "profil_perso", methods: ["GET"])] public function baseProfil(): Response { - try { - $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); - } catch (\Exception $e) { - return $this->redirectToRoute('app_login'); - } + $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); return $this->redirectToRoute('profil_show', ['id' => $this->getUser()->getId()]); } #[Route('/profil/{id}', name: 'profil_show', requirements: ['page' => '\d+'])] From 031def0724468369a459d77df42018e68c45119c Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Thu, 13 Jun 2024 09:52:19 +0200 Subject: [PATCH 4/5] Connection check --- src/Controller/ProfilController.php | 40 +++++++++++------------------ src/Form/ProfilType.php | 1 - templates/profil/edit.html.twig | 4 +-- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index 3d7d5c1..1df6d25 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -25,11 +25,10 @@ class ProfilController extends AbstractController $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); return $this->redirectToRoute('profil_show', ['id' => $this->getUser()->getId()]); } - #[Route('/profil/{id}', name: 'profil_show', requirements: ['page' => '\d+'])] + #[Route('/profil/{id}', name: 'profil_show', requirements: ['id' => '\d+'])] public function profil(int $id): Response { $connected = $this->isGranted('ROLE_USER'); - // $connected = $this->isGranted('ROLE_USER') != false; $profil = $this->mgr->find(Profil::class, $id); $posts = $profil->getPosts(); @@ -46,11 +45,7 @@ class ProfilController extends AbstractController #[Route('/profil/post/follow', name: 'profil_post_follow')] public function postProfilfollow(): Response { - try{ - $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); - }catch (\Exception $e){ - return $this->redirectToRoute('app_login'); - } + $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); $profil = $this->getUser(); $posts = $this->postRepository->getPostFromFollowed($profil); return $this->render('post/all.html.twig', [ @@ -62,11 +57,7 @@ class ProfilController extends AbstractController #[Route('/profil/{id}/unfollow', name: 'profil_unfollow', requirements: ['page' => '\d+'])] public function unfollowProfil(int $id): Response { - try{ - $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); - }catch (\Exception $e){ - return $this->redirectToRoute('app_login'); - } + $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); $profil = $this->mgr->find(Profil::class, $id); if ($profil instanceof Profil) { $profil->removeFollower($this->getUser()); @@ -127,11 +118,7 @@ class ProfilController extends AbstractController #[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])] public function followProfil(int $id): Response { - try{ - $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); - }catch (\Exception $e){ - return $this->redirectToRoute('app_login'); - } + $this->denyAccessUnlessGranted('IS_AUTHENTICATED'); $profil = $this->mgr->find(Profil::class, $id); if ($profil instanceof Profil) { @@ -148,22 +135,25 @@ class ProfilController extends AbstractController } } - #[Route('/profil/{id}/delete', name: 'profil_delete', methods: ['POST'], requirements: ['id' => '\d+'])] - public function delete(int $id, Request $request): Response + #[Route('/profil/delete', name: 'profil_delete', methods: ['POST'])] + public function delete(Request $request): Response { - $profil = $this->mgr->find(Profil::class, $id); + $profil = $this->mgr->find(Profil::class, $this->getUser()->getId()); if (!$profil) { throw $this->createNotFoundException('The profile does not exist'); } - if ($this->isCsrfTokenValid('delete' . $profil->getId(), $request->request->get('_token'))) { - $this->mgr->remove($profil); - $this->mgr->flush(); - $this->addFlash('success', 'Profile deleted successfully'); + if ($this->getUser()->getId() === $profil->getId()) + { + + $this->getUser()->eraseCredentials(); + //$this->mgr->remove($profil); + //$this->mgr->flush(); + return $this->redirectToRoute('app_logout'); } - return $this->redirectToRoute('app_login'); + return $this->redirectToRoute('app_logout'); } diff --git a/src/Form/ProfilType.php b/src/Form/ProfilType.php index d6d5f2e..6f18ba9 100644 --- a/src/Form/ProfilType.php +++ b/src/Form/ProfilType.php @@ -16,7 +16,6 @@ class ProfilType extends AbstractType ->add('name') ->add('description') // ->add('password') - ; } diff --git a/templates/profil/edit.html.twig b/templates/profil/edit.html.twig index 6806fec..1202d46 100644 --- a/templates/profil/edit.html.twig +++ b/templates/profil/edit.html.twig @@ -18,8 +18,8 @@ {{ form_end(form) }} -
- + +
From 35ad046fe13409ab6a43d7e03c6b1a1d93e6967a Mon Sep 17 00:00:00 2001 From: "aurian.jault" Date: Thu, 13 Jun 2024 12:10:22 +0200 Subject: [PATCH 5/5] Deleting acount --- src/Controller/ProfilController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index 1df6d25..9e94137 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -146,10 +146,10 @@ class ProfilController extends AbstractController if ($this->getUser()->getId() === $profil->getId()) { - - $this->getUser()->eraseCredentials(); - //$this->mgr->remove($profil); - //$this->mgr->flush(); + $this->container->get('security.token_storage')->setToken(null); + //$this->getUser()->eraseCredentials(); + $this->mgr->remove($profil); + $this->mgr->flush(); return $this->redirectToRoute('app_logout'); }