added check on login

This commit is contained in:
Charles 2025-10-27 14:01:50 +01:00
parent c54df8a327
commit 772b920a44
1 changed files with 17 additions and 0 deletions

View File

@ -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.');
}
}
}