fix: enforce profile completion of applicant in all situations
This commit is contained in:
@@ -5,8 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace App\Controller\Booking\Create;
|
namespace App\Controller\Booking\Create;
|
||||||
|
|
||||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||||
use App\Controller\Account\PersonalDataController;
|
|
||||||
use App\Entity\User;
|
|
||||||
use App\Exception\HotelNotFoundException;
|
use App\Exception\HotelNotFoundException;
|
||||||
use App\Exception\HotelNotInTravelException;
|
use App\Exception\HotelNotInTravelException;
|
||||||
use App\Exception\NoRoomsAvailableException;
|
use App\Exception\NoRoomsAvailableException;
|
||||||
@@ -44,7 +42,6 @@ class IndexController extends AbstractController
|
|||||||
*
|
*
|
||||||
* Renders a loading page that triggers the actual initialization via HTMX.
|
* Renders a loading page that triggers the actual initialization via HTMX.
|
||||||
* This provides immediate visual feedback while BusProNet API calls are made.
|
* This provides immediate visual feedback while BusProNet API calls are made.
|
||||||
* Redirects to profile completion if logged-in user has incomplete profile data.
|
|
||||||
*/
|
*/
|
||||||
#[Route(
|
#[Route(
|
||||||
path: '/bookings/create',
|
path: '/bookings/create',
|
||||||
@@ -56,14 +53,6 @@ class IndexController extends AbstractController
|
|||||||
throw $this->createNotFoundException('Invalid booking parameters provided');
|
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', [
|
return $this->render('booking/create/index.html.twig', [
|
||||||
'params' => $params,
|
'params' => $params,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\EventListener;
|
||||||
|
|
||||||
|
use App\Controller\Account\PersonalDataController;
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Htmx\HxRedirectResponse;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects users with incomplete profiles to the personal data page after login.
|
||||||
|
*
|
||||||
|
* When a user logs in with an incomplete profile during a booking flow, this listener
|
||||||
|
* intercepts the redirect to store the original target URL and redirects to the
|
||||||
|
* profile completion page instead. After completing their profile, users are
|
||||||
|
* redirected back to their original destination.
|
||||||
|
*/
|
||||||
|
class ProfileCompletionRedirectListener implements EventSubscriberInterface
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly UrlGeneratorInterface $urlGenerator,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getSubscribedEvents(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
LoginSuccessEvent::class => ['onLoginSuccess', 0],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onLoginSuccess(LoginSuccessEvent $event): void
|
||||||
|
{
|
||||||
|
$user = $event->getUser();
|
||||||
|
|
||||||
|
if (false === $user instanceof User || true === $user->isProfileComplete()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = $event->getRequest();
|
||||||
|
$session = $request->getSession();
|
||||||
|
|
||||||
|
// Get the intended target path (set by SecurityController or authenticator)
|
||||||
|
$targetPath = $session->get('_security.main.target_path');
|
||||||
|
|
||||||
|
// Store target path for redirect after profile completion
|
||||||
|
if (null !== $targetPath) {
|
||||||
|
$session->set(PersonalDataController::SESSION_REDIRECT_KEY, $targetPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate personal data URL
|
||||||
|
$personalDataUrl = $this->urlGenerator->generate('app_personal_data');
|
||||||
|
|
||||||
|
// Use HTMX-aware redirect if this is an HTMX request
|
||||||
|
if (true === $request->headers->has('HX-Request')) {
|
||||||
|
$event->setResponse(new HxRedirectResponse($personalDataUrl));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$event->setResponse(new RedirectResponse($personalDataUrl));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
} %}
|
} %}
|
||||||
|
|
||||||
{# hx-boost disabled for cross-origin #}
|
{# hx-boost disabled for cross-origin #}
|
||||||
<a href="{{ returnUrl }}" hx-boost="false" class="button button--secondary">
|
<a href="{{ returnUrl }}" hx-boost="false" class="button button--primary">
|
||||||
Zurück
|
Zurück
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user