app/Customize/EventListener/LogoutEventListener.php line 19

Open in your IDE?
  1. <?php
  2. namespace Customize\EventListener;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Security\Http\Event\LogoutEvent;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Customize\Service\LogoutDebugService;
  7. class LogoutEventListener implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents()
  10.     {
  11.         return [
  12.             LogoutEvent::class => 'onLogout',
  13.         ];
  14.     }
  15.     public function onLogout(LogoutEvent $event)
  16.     {
  17.         $request $event->getRequest();
  18.         $response $event->getResponse();
  19.         
  20.         // DEBUG: Log thông tin LogoutEvent
  21.         var_dump('=== DEBUG LOGOUT EVENT ===');
  22.         var_dump('Event Type: LogoutEvent');
  23.         var_dump('Request Path: ' $request->getPathInfo());
  24.         var_dump('Is Admin Path: ' . ($request->getPathInfo()->startsWith('/admin') ? 'true' 'false'));
  25.         var_dump('Response Status: ' $response->getStatusCode());
  26.         var_dump('=== END DEBUG LOGOUT EVENT ===');
  27.         
  28.         // Sử dụng LogoutDebugService để ghi log
  29.         $debugService = new LogoutDebugService();
  30.         $debugService->logLogoutEvent('LogoutEvent', [
  31.             'path' => $request->getPathInfo(),
  32.             'is_admin' => $request->getPathInfo()->startsWith('/admin'),
  33.             'response_status' => $response->getStatusCode()
  34.         ]);
  35.         
  36.         // Chỉ xử lý cho customer logout, không phải admin
  37.         if (!$request->getPathInfo()->startsWith('/admin')) {
  38.             $host $request->getHost();
  39.             $isSecure $request->isSecure();
  40.             
  41.             // Đảm bảo cookie remember_me được xóa với thuộc tính chính xác
  42.             // Cookie có thuộc tính: Domain=hosting name, Path=/, Secure=true, HttpOnly=true, Priority=Medium
  43.             $response->headers->clearCookie('eccube_remember_me''/'$host$isSecuretruefalsetrue);
  44.             
  45.             // Xóa session login_memory
  46.             $session $request->getSession();
  47.             if ($session) {
  48.                 $session->remove('_security.login_memory');
  49.             }
  50.             
  51.             error_log('LogoutEventListener: Cookie remember_me đã được xóa cho path: ' $request->getPathInfo() . ' với host: ' $host ', secure: ' . ($isSecure 'true' 'false') . ', domain: ' $host);
  52.         }
  53.     }
  54. }