feat: move profile completeness check from login to booking flow entry
- Add profileComplete flag to User entity to avoid API calls - Set flag during login (BpnAuthenticator) and profile save - Check flag in IndexController when entering booking flow - Remove ProfileCompletionSubscriber (no longer needed) Users with incomplete profiles are only redirected when starting a new booking, not on every login. Eliminates extra API call by caching completeness status on the user entity.
This commit is contained in:
@@ -9,6 +9,7 @@ use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Entity\User;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\ProfileCompletenessChecker;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
@@ -41,6 +42,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly Crypt $crypt,
|
||||
private readonly ProfileCompletenessChecker $completenessChecker,
|
||||
private readonly LoggerInterface $authLogger,
|
||||
) {
|
||||
}
|
||||
@@ -72,7 +74,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
|
||||
return new SelfValidatingPassport(
|
||||
new UserBadge($email, function () use ($email, $password, $response) {
|
||||
return $this->createOrUpdateLocalUser($email, $password, $response->personId, $response->addressId);
|
||||
return $this->createOrUpdateLocalUser($email, $password, $response);
|
||||
}),
|
||||
[
|
||||
new CsrfTokenBadge('authenticate', $csrfToken),
|
||||
@@ -80,7 +82,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
);
|
||||
}
|
||||
|
||||
private function createOrUpdateLocalUser(string $email, string $password, ?int $personId, ?int $addressId): User
|
||||
private function createOrUpdateLocalUser(string $email, string $password, PersonalData $personalData): User
|
||||
{
|
||||
try {
|
||||
$crmAttributes = $this->apiClient->getCrmAttributes($email, $password);
|
||||
@@ -102,11 +104,12 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
|
||||
$user
|
||||
->setPassword($encryptedPassword)
|
||||
->setPersonId($personId)
|
||||
->setAddressId($addressId)
|
||||
->setPersonId($personalData->personId)
|
||||
->setAddressId($personalData->addressId)
|
||||
->setRoles($roles)
|
||||
->setHotelCodes($hotelCodes)
|
||||
->setLastLoginAt(new \DateTimeImmutable())
|
||||
->setProfileComplete($this->completenessChecker->isComplete($personalData))
|
||||
;
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
Reference in New Issue
Block a user