fix conflicts for merge

pull/23/head
remrem 11 months ago
commit 5717b1b1c0

@ -62,4 +62,9 @@ hr {
display: flex; display: flex;
flex-grow: 1; flex-grow: 1;
} }
a {
text-decoration: none;
color: black;
}
} }

@ -6,9 +6,18 @@
padding: 20px; padding: 20px;
transition: .3s; transition: .3s;
a {
text-decoration: none;
color: black;
}
&.nightmare { &.nightmare {
background-color: #1b1447; background-color: #1b1447;
color: white; color: white;
a {
color: white;
}
} }
} }
@ -33,8 +42,3 @@
font-size: 1em; font-size: 1em;
} }
} }
a {
text-decoration: none;
color: black;
}

@ -6,7 +6,6 @@ use App\Entity\Profil;
use App\Form\ProfilType; use App\Form\ProfilType;
use App\Repository\PostRepository; use App\Repository\PostRepository;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use SebastianBergmann\Environment\Console;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
@ -20,19 +19,14 @@ class ProfilController extends AbstractController
#[Route(path: "/profil", name: "profil_perso", methods: ["GET"])] #[Route(path: "/profil", name: "profil_perso", methods: ["GET"])]
public function baseProfil(): Response public function baseProfil(): Response
{ {
try { $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
} catch (\Exception $e) {
return $this->redirectToRoute('app_login');
}
return $this->redirectToRoute('profil_show', ['id' => $this->getUser()->getId()]); 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 public function profil(int $id): Response
{ {
$connected = $this->isGranted('ROLE_USER'); $connected = $this->isGranted('ROLE_USER');
// $connected = $this->isGranted('ROLE_USER') != false;
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
$posts = $profil->getPosts(); $posts = $profil->getPosts();
@ -48,11 +42,7 @@ class ProfilController extends AbstractController
#[Route('/profil/post/follow', name: 'profil_post_follow')] #[Route('/profil/post/follow', name: 'profil_post_follow')]
public function postProfilfollow(): Response public function postProfilfollow(): Response
{ {
try{ $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->getUser(); $profil = $this->getUser();
$posts = $this->postRepository->getPostFromFollowed($profil); $posts = $this->postRepository->getPostFromFollowed($profil);
return $this->render('post/all.html.twig', [ 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+'])] #[Route('/profil/{id}/unfollow', name: 'profil_unfollow', requirements: ['page' => '\d+'])]
public function unfollowProfil(int $id): Response public function unfollowProfil(int $id): Response
{ {
try{ $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) { if ($profil instanceof Profil) {
$profil->removeFollower($this->getUser()); $profil->removeFollower($this->getUser());
@ -130,11 +115,7 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])] #[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])]
public function followProfil(int $id): Response public function followProfil(int $id): Response
{ {
try{ $this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) { if ($profil instanceof Profil) {
@ -151,21 +132,24 @@ class ProfilController extends AbstractController
} }
} }
#[Route('/profil/{id}/delete', name: 'profil_delete', methods: ['POST'], requirements: ['id' => '\d+'])] #[Route('/profil/delete', name: 'profil_delete', methods: ['POST'])]
public function delete(int $id, Request $request): Response public function delete(): Response
{ {
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $this->getUser()->getId());
if (!$profil) { if (!$profil) {
throw $this->createNotFoundException('The profile does not exist'); 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->remove($profil);
$this->mgr->flush(); $this->mgr->flush();
$this->addFlash('success', 'Profile deleted successfully'); return $this->redirectToRoute('app_logout');
} }
return $this->redirectToRoute('app_login'); return $this->redirectToRoute('app_logout');
} }
} }

@ -16,7 +16,6 @@ class ProfilType extends AbstractType
->add('name') ->add('name')
->add('description') ->add('description')
// ->add('password') // ->add('password')
; ;
} }

@ -16,8 +16,10 @@
<div id="post-wrapper" class="{% if post.dream %}nightmare{% endif %}"> <div id="post-wrapper" class="{% if post.dream %}nightmare{% endif %}">
<div id="post"> <div id="post">
<div id="post-info"> <div id="post-info">
<img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ post.profil.name }}" width="50px"> <a href="{{ path('profil_show', {'id': post.profil.id}) }}">
<span>{{ post.profil.name }}</span> <img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ post.profil.name }}" width="50px">
</a>
<span>{{ post.profil.name }}</span>
{# <span>- {{ post.dateCreated }}</span> #} {# <span>- {{ post.dateCreated }}</span> #}
<span>-</span> <span>-</span>
<span>{{ post.createdAt|date('l, F j, Y') }}</span> <span>{{ post.createdAt|date('l, F j, Y') }}</span>

@ -1,18 +1,20 @@
{% block body %} {% block body %}
<a href="{{ path('display_post', {'id': post.id}) }}">
<div id="post-wrapper" class="{% if post.dream %}nightmare{% endif %}"> <div id="post-wrapper" class="{% if post.dream %}nightmare{% endif %}">
<div id="post"> <div id="post">
<div id="post-info"> <div id="post-info">
<img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ post.profil.name }}" width="40px"> <a href="{{ path('profil_show', {'id': post.profil.id}) }}">
<span>{{ post.profil.name }}</span> <img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ post.profil.name }}" width="40px">
</a>
<span>{{ post.profil.name }}</span>
{# <span>- {{ post.dateCreated }}</span> #} {# <span>- {{ post.dateCreated }}</span> #}
<span>-</span> <span>-</span>
<span>{{ post.createdAt|date('l, F j, Y') }}</span> <span>{{ post.createdAt|date('l, F j, Y') }}</span>
</div> </div>
<h1 id="post-title">{{ post.title }}</h1> <a href="{{ path('display_post', {'id': post.id}) }}">
<p>{{ post.text|u.truncate(150, '...', false) }}</p> <h1 id="post-title">{{ post.title }}</h1>
<p>{{ post.text|u.truncate(150, '...', false) }}</p>
</a>
</div> </div>
</div> </div>
</a>
{% endblock %} {% endblock %}

@ -18,8 +18,8 @@
<button type="submit" class="btn btn-primary follow-button">Save</button> <button type="submit" class="btn btn-primary follow-button">Save</button>
{{ form_end(form) }} {{ form_end(form) }}
<form method="post" action="{{ path('profil_delete', {id: profil.id}) }}" onsubmit="return confirm('Are you sure you want to delete this profile?');"> <form method="post" action="{{ path('profil_delete') }}" onsubmit="return confirm('Are you sure you want to delete this profile?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ profil.id) }}"> <input type="hidden" name="_token" value="{{ csrf_token('delete') }}">
<button class="btn btn-danger delete-button">Delete Profile</button> <button class="btn btn-danger delete-button">Delete Profile</button>
</form> </form>
</div> </div>

Binary file not shown.
Loading…
Cancel
Save