diff --git a/public/css/components/post.css b/public/css/components/post.css index 3559f3f..d8c7f57 100644 --- a/public/css/components/post.css +++ b/public/css/components/post.css @@ -62,4 +62,9 @@ hr { display: flex; flex-grow: 1; } + + a { + text-decoration: none; + color: black; + } } \ No newline at end of file diff --git a/public/css/components/post_mini.css b/public/css/components/post_mini.css index 68d83f6..4d52c60 100644 --- a/public/css/components/post_mini.css +++ b/public/css/components/post_mini.css @@ -6,9 +6,18 @@ padding: 20px; transition: .3s; + a { + text-decoration: none; + color: black; + } + &.nightmare { background-color: #1b1447; color: white; + + a { + color: white; + } } } @@ -33,8 +42,3 @@ font-size: 1em; } } - -a { - text-decoration: none; - color: black; -} \ No newline at end of file diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index e918269..2896ab8 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -6,7 +6,6 @@ use App\Entity\Profil; use App\Form\ProfilType; use App\Repository\PostRepository; use Doctrine\ORM\EntityManager; -use SebastianBergmann\Environment\Console; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -20,19 +19,14 @@ 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+'])] + #[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(); @@ -48,11 +42,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', [ @@ -64,12 +54,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()); @@ -130,11 +115,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) { @@ -151,21 +132,24 @@ 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(): 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'))) { + if ($this->getUser()->getId() === $profil->getId()) + { + $this->container->get('security.token_storage')->setToken(null); + //$this->getUser()->eraseCredentials(); $this->mgr->remove($profil); $this->mgr->flush(); - $this->addFlash('success', 'Profile deleted successfully'); + 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/post/post.html.twig b/templates/post/post.html.twig index 2ba5e06..29abeb3 100644 --- a/templates/post/post.html.twig +++ b/templates/post/post.html.twig @@ -16,8 +16,10 @@
- - {{ post.profil.name }} + + + + {{ post.profil.name }} {# - {{ post.dateCreated }} #} - {{ post.createdAt|date('l, F j, Y') }} diff --git a/templates/post/post_mini.html.twig b/templates/post/post_mini.html.twig index b81faf9..a45013f 100644 --- a/templates/post/post_mini.html.twig +++ b/templates/post/post_mini.html.twig @@ -1,18 +1,20 @@ {% block body %} -
- - {{ post.profil.name }} + + + + {{ post.profil.name }} {# - {{ post.dateCreated }} #} - {{ post.createdAt|date('l, F j, Y') }}
-

{{ post.title }}

-

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

+ +

{{ post.title }}

+

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

+
- {% endblock %} 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) }} -
- + +
diff --git a/var/data.db b/var/data.db index 1a09c2a..c721252 100644 Binary files a/var/data.db and b/var/data.db differ