fix: never persist a half-built user on first login

This commit is contained in:
Björn Fromme
2026-08-19 12:30:42 +02:00
parent 0c667d6b69
commit 2601e46ec4
4 changed files with 218 additions and 26 deletions
+8 -7
View File
@@ -106,13 +106,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
$userRepository = $this->entityManager->getRepository(User::class);
if (null === $user = $userRepository->findOneBy(['email' => $email])) {
$user = new User($email);
$this->entityManager->persist($user);
}
$this->syncFromCrm($user, $crmAttributes);
$user = $userRepository->findOneBy(['email' => $email]) ?? new User($email);
$user
->setPassword($encryptedPassword)
@@ -124,6 +118,13 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
->setProfileComplete($this->completenessChecker->isComplete($personalData))
;
$this->syncFromCrm($user, $crmAttributes);
// Registered only once it is fully populated: syncFromCrm() logs on a channel that writes
// to the database, and an account already managed at that point would be flushed
// half-built — which is how a NULL password used to reach the user table. A no-op for an
// account that came from the repository.
$this->entityManager->persist($user);
$this->entityManager->flush();
return $user;