revoke user token if he is deleted

This commit is contained in:
Charles 2025-10-27 11:10:32 +01:00
parent 5a39804dd4
commit 2d7adf20ec
2 changed files with 15 additions and 0 deletions

View File

@ -325,6 +325,9 @@ class UserController extends AbstractController
$user->setModifiedAt(new \DateTimeImmutable('now'));
$this->userOrganizationService->deactivateAllUserOrganizationLinks($user, $actingUser);
$user->setIsDeleted(true);
if($this->userService->isUserConnected($user)){
$this->userService->revokeUserTokens($user->getUserIdentifier());
}
$this->entityManager->persist($user);
$this->entityManager->flush();
$this->actionService->createAction("Delete user", $actingUser, null, $user->getUserIdentifier());

View File

@ -367,4 +367,16 @@ class UserService
}
return 'ROLE_' . $role;
}
public function revokeUserTokens(String $userIdentifier)
{
$tokens = $this->entityManager->getRepository(AccessToken::class)->findBy([
'userIdentifier' => $userIdentifier,
'revoked' => false
]);
foreach ($tokens as $token) {
$token->revoke();
}
}
}