diff --git a/config/packages/security.yaml b/config/packages/security.yaml index d161141..5efb890 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -45,6 +45,7 @@ security: - { path: ^/login, roles: PUBLIC_ACCESS } - { path: ^/password, roles: PUBLIC_ACCESS } - { path: ^/register, roles: PUBLIC_ACCESS } + - { path: ^/inscription, roles: PUBLIC_ACCESS } - { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/, roles: ROLE_USER } diff --git a/migrations/Version20241120093750.php b/migrations/Version20241120093750.php deleted file mode 100644 index 3e1d6b3..0000000 --- a/migrations/Version20241120093750.php +++ /dev/null @@ -1,33 +0,0 @@ -addSql('CREATE TABLE password_reset_token (id_password_reset_token CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', token VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL, email VARCHAR(255) NOT NULL, PRIMARY KEY(id_password_reset_token)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE participant DROP file_name'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE password_reset_token'); - $this->addSql('ALTER TABLE participant ADD file_name VARCHAR(255) DEFAULT NULL'); - } -} diff --git a/migrations/Version20241120095413.php b/migrations/Version20241120131557.php similarity index 72% rename from migrations/Version20241120095413.php rename to migrations/Version20241120131557.php index 86bddab..3ee181e 100644 --- a/migrations/Version20241120095413.php +++ b/migrations/Version20241120131557.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20241120095413 extends AbstractMigration +final class Version20241120131557 extends AbstractMigration { public function getDescription(): string { @@ -20,12 +20,12 @@ final class Version20241120095413 extends AbstractMigration public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE participant ADD file_name VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE participant ADD pending TINYINT(1) NOT NULL'); } public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE participant DROP file_name'); + $this->addSql('ALTER TABLE participant DROP pending'); } } diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index a079db9..364712d 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -9,6 +9,7 @@ use App\Entity\Ville; use App\Repository\ParticipantRepository; use App\Repository\SiteRepository; use App\Repository\VilleRepository; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -376,4 +377,49 @@ class AdminController extends AbstractController $this->addFlash('success', 'Site supprimée avec succès.'); return $this->redirectToRoute('app_adminSite'); } + + #[Route('/admin/accept', name: 'app_acceptUser')] + public function acceptUser(Request $request, EntityManagerInterface $entityManager, ParticipantRepository $participantRepository): Response + { + try { + $user = $participantRepository->findOneBy(["idParticipant" => $request->get('id')]); + + if(!$user) { + $this->addFlash('error', 'Le utilisateur n\'existe pas.'); + return $this->redirectToRoute('app_adminUser'); + } + + $user->setPending(false); + $entityManager->persist($user); + $entityManager->flush(); + + $this->addFlash('success', "L'utilisateur à bien été accepté et peut maintenant se connecter"); + return $this->redirectToRoute('app_adminUser'); + } catch(\Exception $e) { + $this->addFlash('error', "Erreur : " . $e->getMessage()); + return $this->redirectToRoute('home'); + } + } + + #[Route('/admin/deny', name: 'app_denyUser')] + public function denyUser(Request $request, EntityManagerInterface $entityManager, ParticipantRepository $participantRepository): Response + { + try { + $user = $participantRepository->findOneBy(["idParticipant" => $request->get('id')]); + + if(!$user) { + $this->addFlash('error', 'Le utilisateur n\'existe pas.'); + return $this->redirectToRoute('app_adminUser'); + } + + $entityManager->remove($user); + $entityManager->flush(); + + $this->addFlash('success', "L'utilisateur à bien été refusé et ne pourra pas se connecter"); + return $this->redirectToRoute('app_adminUser'); + } catch(\Exception $e) { + $this->addFlash('error', "Erreur : " . $e->getMessage()); + return $this->redirectToRoute('home'); + } + } } diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 559e3ff..3afda40 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -18,4 +18,10 @@ class MainController extends AbstractController 'profile' => $userConnect, ]); } + + #[Route('/inscription', name: 'inscription')] + public function inscription(TokenStorageInterface $tokenStorage): Response + { + return $this->render('main/inscription.html.twig'); + } } diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index f0ad780..6d86c52 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -31,6 +31,7 @@ class RegistrationController extends AbstractController $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); $user->setRoles(['ROLE_USER']); $user->setActif(false); + $user->setPending(true); if ($user->getRoles() == 'ROLE_ADMIN') { $user->setAdministrateur(true); } else { @@ -47,8 +48,8 @@ class RegistrationController extends AbstractController // do anything else you need here, like send an email -// return $this->redirectToRoute('home'); - return $security->login($user, 'form_login', 'main'); + return $this->redirectToRoute('inscription'); +// return $security->login($user, 'form_login', 'main'); } return $this->render('auth/register.html.twig', [ diff --git a/src/Entity/Participant.php b/src/Entity/Participant.php index b8273be..e7f6165 100644 --- a/src/Entity/Participant.php +++ b/src/Entity/Participant.php @@ -41,6 +41,9 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column] private ?bool $actif = null; + #[ORM\Column] + private ?bool $pending = null; + #[ORM\Column] private array $roles = []; @@ -82,6 +85,16 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + public function getPending(): ?bool + { + return $this->pending; + } + + public function setPending(?bool $pending): void + { + $this->pending = $pending; + } + public function getPseudo(): ?string { return $this->pseudo; diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index 082013b..afb23bb 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -46,7 +46,7 @@ class LoginFormAuthenticator extends AbstractAuthenticator 'pseudo' => $identifier ]); - if (!$user || $user->isActif()) { + if (!$user || $user->isActif() || $user->getPending()) { throw new UserNotFoundException('Utilisateur non trouvé'); } diff --git a/templates/admin/user.html.twig b/templates/admin/user.html.twig index 18a7643..ad4f743 100644 --- a/templates/admin/user.html.twig +++ b/templates/admin/user.html.twig @@ -59,6 +59,7 @@ {% for participant in participants %} + {% if not participant.pending %} {{ participant.nom }} {{ participant.prenom }} @@ -81,6 +82,7 @@ Supprimer + {% endif %} {% else %} Aucun participant trouvé @@ -89,8 +91,48 @@ + {# Tableau user en attente #} +
+ + + + + + + + + + + + + {% for participant in participants %} + {% if participant.pending %} + + + + + + + + + {% endif %} + {% else %} + + + + {% endfor %} + +
NomPrénomPseudoTéléphoneEmailActions
{{ participant.nom }}{{ participant.prenom }}{{ participant.pseudo }}{{ participant.telephone }}{{ participant.email }} + + Accepter + + Refuser +
Aucun participant en attente
+
- + + +