Adding roles and redirect on logout

pull/11/head
Aurian JAULT 11 months ago
parent 76726e4b61
commit b001f7ecd8

@ -22,8 +22,7 @@ security:
enable_csrf: true
logout:
path: app_logout
# where to redirect after logout
# target: app_any_route
target: /login
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
@ -34,8 +33,9 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
#- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/logout, role: ROLE_USER}
when@test:
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');
}
}

@ -29,6 +29,7 @@ class RegistrationController extends AbstractController
$form->get('plainPassword')->getData()
)
);
$user->setRoles(['ROLE_USER']);
$entityManager->persist($user);
$entityManager->flush();

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

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

Loading…
Cancel
Save