From 772b920a4455bd8ac41f952f705ca4be51425ced Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 27 Oct 2025 14:01:50 +0100 Subject: [PATCH] added check on login --- src/Security/UserChecker.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Security/UserChecker.php b/src/Security/UserChecker.php index b7f4ca4..e305e97 100644 --- a/src/Security/UserChecker.php +++ b/src/Security/UserChecker.php @@ -2,12 +2,18 @@ // src/Security/UserChecker.php namespace App\Security; +use App\Entity\UsersOrganizations; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException; class UserChecker implements UserCheckerInterface { + public function __construct(private readonly EntityManagerInterface $entityManager) + { + } + public function checkPreAuth(UserInterface $user): void { // runs before password is checked @@ -19,5 +25,16 @@ class UserChecker implements UserCheckerInterface if (method_exists($user, 'isDeleted') && $user->isDeleted()) { throw new CustomUserMessageAccountStatusException('Votre compte a été supprimé.'); } + + // check if the user account is active + if (method_exists($user, 'isActive') && $user->isActive()) { + throw new CustomUserMessageAccountStatusException('Votre compte est désactivé.'); + } + + //check if the user is in an organization + $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy(['users' => $user, 'isDeleted' => true]); + if ($uo === null) { + throw new CustomUserMessageAccountStatusException('Vous n\'êtes pas relié à une organisation. veuillez contacter un administrateur.'); + } } } \ No newline at end of file