pull/16/head
Corentin RICHARD 11 months ago
commit 931275435b

@ -21,10 +21,10 @@ security:
login_path: app_login login_path: app_login
check_path: app_login check_path: app_login
enable_csrf: true enable_csrf: true
default_target_path: all post
logout: logout:
path: app_logout path: app_logout
# where to redirect after logout target: /login
# target: app_any_route
# activate different ways to authenticate # activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall # https://symfony.com/doc/current/security.html#the-firewall
@ -35,8 +35,9 @@ security:
# Easy way to control access for large sections of your site # Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used # Note: Only the *first* access control that matches will be used
access_control: access_control:
# - { path: ^/admin, roles: ROLE_ADMIN } #- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/profile, roles: ROLE_USER } #- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/logout, role: ROLE_USER}
when@test: when@test:
security: security:

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240612112105 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE profil ADD COLUMN roles CLOB DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__profil AS SELECT id, name, description, password FROM profil');
$this->addSql('DROP TABLE profil');
$this->addSql('CREATE TABLE profil (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, password VARCHAR(255) DEFAULT NULL)');
$this->addSql('INSERT INTO profil (id, name, description, password) SELECT id, name, description, password FROM __temp__profil');
$this->addSql('DROP TABLE __temp__profil');
}
}

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240612121601 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE profil ADD COLUMN roles CLOB DEFAULT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__profil AS SELECT id, name, description, password FROM profil');
$this->addSql('DROP TABLE profil');
$this->addSql('CREATE TABLE profil (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, password VARCHAR(255) DEFAULT NULL)');
$this->addSql('INSERT INTO profil (id, name, description, password) SELECT id, name, description, password FROM __temp__profil');
$this->addSql('DROP TABLE __temp__profil');
}
}

@ -21,7 +21,7 @@ class PostController extends AbstractController
} }
# DEBUG: Ne doit pas être laissé en production. # DEBUG: Ne doit pas être laissé en production.
#[Route('/post/all', name: 'all post', methods: ['GET'])] #[Route('/', name: 'all post', methods: ['GET'])]
public function getAllPost(): Response public function getAllPost(): Response
{ {
$posts = $this->em->getRepository(Post::class)->findAll(); $posts = $this->em->getRepository(Post::class)->findAll();
@ -52,6 +52,8 @@ class PostController extends AbstractController
#[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])] #[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])]
public function addPost(Request $request): Response public function addPost(Request $request): Response
{ {
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
$post = new Post(); $post = new Post();
$form = $this->createForm(PostType::class, $post); $form = $this->createForm(PostType::class, $post);
@ -65,8 +67,7 @@ class PostController extends AbstractController
$this->em->persist($post); $this->em->persist($post);
$this->em->flush(); $this->em->flush();
return $this->redirectToRoute('display post', ['id' => $post->getId()]);
return new Response($user->getUserIdentifier());
} }
return $this->render('post/new.html.twig', [ return $this->render('post/new.html.twig', [

@ -28,8 +28,8 @@ class RegistrationController extends AbstractController
$user, $user,
$form->get('plainPassword')->getData() $form->get('plainPassword')->getData()
); );
$user->setRoles(['ROLE_USER']);
$user->setPassword($hashedPassword); $user->setPassword($hashedPassword);
$entityManager->persist($user); $entityManager->persist($user);
$entityManager->flush(); $entityManager->flush();

@ -19,6 +19,7 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column] #[ORM\Column]
private ?int $id = null; private ?int $id = null;
#[ORM\Column(type: 'json', nullable: true)]
private array $roles = []; private array $roles = [];
#[ORM\Column(length: 255, nullable: true)] #[ORM\Column(length: 255, nullable: true)]
@ -176,7 +177,7 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface
{ {
$roles = $this->roles; $roles = $this->roles;
// guarantee every user at least has ROLE_USER // guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER'; // $roles[] = 'ROLE_USER';
return array_unique($roles); return array_unique($roles);
} }
@ -184,10 +185,14 @@ class Profil implements UserInterface, PasswordAuthenticatedUserInterface
public function setRoles(array $roles): self public function setRoles(array $roles): self
{ {
$this->roles = $roles; $this->roles = $roles;
return $this; return $this;
} }
public function getUserIdentifier(): string
{
return $this->name;
}
public function eraseCredentials(): void public function eraseCredentials(): void
{ {
// TODO: Implement eraseCredentials() method. // TODO: Implement eraseCredentials() method.

@ -9,7 +9,7 @@ use Doctrine\Persistence\ManagerRegistry;
/** /**
* @extends ServiceEntityRepository<Tags> * @extends ServiceEntityRepository<Tags>
*/ */
class agsRepository extends ServiceEntityRepository class TagsRepository extends ServiceEntityRepository
{ {
public function __construct(ManagerRegistry $registry) public function __construct(ManagerRegistry $registry)
{ {

Loading…
Cancel
Save