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:
Björn Fromme
2026-03-16 12:02:59 +01:00
parent 7d3a63d744
commit c582e0820a
6 changed files with 76 additions and 114 deletions
@@ -9,11 +9,11 @@ use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\Notification;
use App\BusProNet\Model\PersonalData;
use App\Entity\User;
use App\EventSubscriber\ProfileCompletionSubscriber;
use App\Form\PersonalDataType;
use App\Security\Crypt;
use App\Service\BookingEditDataLoaderService;
use App\Service\ProfileCompletenessChecker;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -30,11 +30,14 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
*/
class PersonalDataController extends AbstractController
{
public const SESSION_REDIRECT_KEY = '_profile_completion_redirect';
/**
* @param ApiClient $apiClient BusProNet API client for data operations
* @param Crypt $crypt Encryption service for password handling
* @param BookingEditDataLoaderService $dataLoader Data loader for cache invalidation
* @param ProfileCompletenessChecker $completenessChecker Profile validation service
* @param EntityManagerInterface $entityManager Entity manager for persisting user changes
* @param LoggerInterface $logger Logger for audit trails and debugging
*/
public function __construct(
@@ -42,6 +45,7 @@ class PersonalDataController extends AbstractController
private readonly Crypt $crypt,
private readonly BookingEditDataLoaderService $dataLoader,
private readonly ProfileCompletenessChecker $completenessChecker,
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger,
) {
}
@@ -100,6 +104,11 @@ class PersonalDataController extends AbstractController
// Invalidate cached bookings to ensure edit mode shows updated applicant data
$this->dataLoader->invalidateUserBookingCaches($user);
// Update profile completeness flag on user entity
$isComplete = $this->completenessChecker->isComplete($personalData);
$user->setProfileComplete($isComplete);
$this->entityManager->flush();
$this->addFlash('success', 'Deine persönlichen Daten wurden aktualisiert');
$this->logger->info('Updated personal data', [
'email' => $user->getEmail(),
@@ -107,10 +116,10 @@ class PersonalDataController extends AbstractController
// Handle profile completion redirect
$session = $request->getSession();
$redirectUrl = $session->get(ProfileCompletionSubscriber::SESSION_REDIRECT_KEY);
$redirectUrl = $session->get(self::SESSION_REDIRECT_KEY);
if (null !== $redirectUrl && true === $this->completenessChecker->isComplete($personalData)) {
$session->remove(ProfileCompletionSubscriber::SESSION_REDIRECT_KEY);
if (null !== $redirectUrl && true === $isComplete) {
$session->remove(self::SESSION_REDIRECT_KEY);
return $this->redirect($redirectUrl);
}
@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Controller\Booking\Create;
use App\BusProNet\XmlLoader\AgencyLoader;
use App\Controller\Account\PersonalDataController;
use App\Entity\User;
use App\Exception\HotelNotFoundException;
use App\Exception\HotelNotInTravelException;
use App\Exception\NoRoomsAvailableException;
@@ -42,17 +44,26 @@ class IndexController extends AbstractController
*
* Renders a loading page that triggers the actual initialization via HTMX.
* This provides immediate visual feedback while BusProNet API calls are made.
* Redirects to profile completion if logged-in user has incomplete profile data.
*/
#[Route(
path: '/bookings/create',
name: 'app_booking_create',
)]
public function index(#[MapQueryString] ?BookingQueryParams $params): Response
public function index(Request $request, #[MapQueryString] ?BookingQueryParams $params): Response
{
if (null === $params) {
throw $this->createNotFoundException('Invalid booking parameters provided');
}
$user = $this->getUser();
if ($user instanceof User && false === $user->isProfileComplete()) {
$request->getSession()->set(PersonalDataController::SESSION_REDIRECT_KEY, $request->getUri());
return $this->redirectToRoute('app_personal_data');
}
return $this->render('booking/create/index.html.twig', [
'params' => $params,
]);