resend correct mail to existing user

This commit is contained in:
Charles 2026-01-28 14:15:17 +01:00
parent 2c7402249d
commit df4363dd37
2 changed files with 48 additions and 44 deletions

View File

@ -168,7 +168,7 @@ class UserController extends AbstractController
// -------------------------------------------------------------------
// Calcul du flag de modification : utilisateur admin ET exactement 1 UO
$canEdit = $this->userService->canEditRolesCheck($actingUser, $user,$this->isGranted('ROLE_ADMIN'), $singleUo, $organization);
$canEdit = $this->userService->canEditRolesCheck($actingUser, $user, $this->isGranted('ROLE_ADMIN'), $singleUo, $organization);
} catch (\Exception $e) {
$this->loggerService->logError('error while loading user information', [
@ -190,7 +190,7 @@ class UserController extends AbstractController
]);
}
#[Route('/edit/{id}', name: 'edit', methods: ['GET','POST'])]
#[Route('/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
public function edit(int $id, Request $request): Response
{
$this->denyAccessUnlessGranted('ROLE_USER');
@ -290,12 +290,12 @@ class UserController extends AbstractController
$this->addFlash('error', "L'organisation n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND);
}
if($this->isGranted('ROLE_ADMIN') && !$this->userService->isAdminOfOrganization($org) && !$this->isGranted('ROLE_SUPER_ADMIN')) {
if ($this->isGranted('ROLE_ADMIN') && !$this->userService->isAdminOfOrganization($org) && !$this->isGranted('ROLE_SUPER_ADMIN')) {
$this->loggerService->logAccessDenied($actingUser->getId());
$this->addFlash('error', "Accès non autorisé.");
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
}
}elseif($this->isGranted('ROLE_ADMIN')) {
} elseif ($this->isGranted('ROLE_ADMIN')) {
$this->loggerService->logAccessDenied($actingUser->getId());
$this->addFlash('error', "Accès non autorisé.");
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
@ -794,7 +794,7 @@ class UserController extends AbstractController
$user = $uo->getUsers();
$initials = $user->getName()[0] . $user->getSurname()[0];
return [
'pictureUrl' =>$user->getPictureUrl(),
'pictureUrl' => $user->getPictureUrl(),
'email' => $user->getEmail(),
'isConnected' => $this->userService->isUserConnected($user->getUserIdentifier()),
'showUrl' => $this->generateUrl('user_show', ['id' => $user->getId()]),
@ -931,6 +931,10 @@ class UserController extends AbstractController
$this->loggerService->logEntityNotFound('User', ['id' => $user->getId()], $actingUser->getId());
throw $this->createNotFoundException(self::NOT_FOUND);
}
$token = $this->userService->generatePasswordToken($user, $org->getId());
if ($user->getLastConnection() !== null) {
$this->userService->sendExistingUserNotifications($user, $org, $actingUser);
} else {
$uo = $this->uoRepository->findOneBy(['users' => $user,
'organization' => $org,
'statut' => "INVITED"]);
@ -943,7 +947,6 @@ class UserController extends AbstractController
$uo->setModifiedAt(new \DateTimeImmutable());
try {
$data = ['user' => $uo->getUsers(), 'organization' => $uo->getOrganization()];
$token = $this->userService->generatePasswordToken($user, $org->getId());
$this->emailService->sendPasswordSetupEmail($user, $token);
$this->loggerService->logEmailSent($userId, $org->getId(), 'Invitation Resent');
$this->organizationsService->notifyOrganizationAdmins($data, 'USER_INVITED');
@ -958,6 +961,7 @@ class UserController extends AbstractController
return $this->json(['message' => 'Erreur lors de l\'envoie du mail.'], Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
}
@ -979,7 +983,7 @@ class UserController extends AbstractController
if (!$user) {
$this->loggerService->logEntityNotFound('User not found in accept invitation', [
'user_id' => $userId
],null);
], null);
throw $this->createNotFoundException(self::NOT_FOUND);
}
if (!$this->userService->isPasswordTokenValid($user, $token)) {

View File

@ -660,7 +660,7 @@ class UserService
}
// Private helpers for email notifications
private function sendExistingUserNotifications(User $user, Organizations $org, User $actingUser): void
public function sendExistingUserNotifications(User $user, Organizations $org, User $actingUser): void
{
try {
$token = $this->generatePasswordToken($user, $org->getId());