src/EventListener/BanCheckSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Doctrine\DBAL\Connection;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  6. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class BanCheckSubscriber implements EventSubscriberInterface
  10. {
  11.     private Connection $connection;
  12.     public function __construct(Connection $connection)
  13.     {
  14.         $this->connection $connection;
  15.     }
  16.     public function onKernelController(ControllerEvent $event): void
  17.     {
  18.         $request $event->getRequest();
  19.         $session $request->getSession();
  20.         $sid $session->get('hash');
  21.         if (!$sid) {
  22.             return;
  23.         }
  24.         $user $this->connection->fetchAssociative(
  25.             'SELECT * FROM users WHERE hash = ?', [$sid]
  26.         );
  27.         if ($user && ($user['ban'] ?? 0) == 1) {
  28.             $event->setController(function () {
  29.             $html = <<<HTML
  30.             <!DOCTYPE html>
  31.             <html lang="ru">
  32.             <head>
  33.                 <meta charset="UTF-8">
  34.                 <meta name="viewport" content="width=device-width, initial-scale=1.0">
  35.                 <title>Аккаунт заблокирован</title>
  36.                 <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
  37.                 <style>
  38.                     @keyframes fadeIn {
  39.                         from {
  40.                             opacity: 0;
  41.                             transform: translateY(-20px);
  42.                         }
  43.                         to {
  44.                             opacity: 1;
  45.                             transform: translateY(0);
  46.                         }
  47.                     }
  48.                     body {
  49.                         background-color: #111827;
  50.                         color: #E5E7EB;
  51.                         font-family: 'Inter', sans-serif;
  52.                         display: flex;
  53.                         align-items: center;
  54.                         justify-content: center;
  55.                         height: 100vh;
  56.                         margin: 0;
  57.                         text-align: center;
  58.                     }
  59.                     .container {
  60.                         background: #1F2937; 
  61.                         padding: 50px;
  62.                         border-radius: 16px;
  63.                         border: 1px solid #374151;
  64.                         box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  65.                         max-width: 500px;
  66.                         width: 90%;
  67.                         animation: fadeIn 0.8s ease-out;
  68.                     }
  69.                     .icon {
  70.                         width: 80px;
  71.                         height: 80px;
  72.                         margin: 0 auto 30px;
  73.                         color: #EF4444; /* Red for the icon */
  74.                     }
  75.                     h1 {
  76.                         font-size: 28px;
  77.                         font-weight: 700;
  78.                         margin: 0 0 15px;
  79.                         color: #F9FAFB; /* White heading */
  80.                     }
  81.                     p {
  82.                         font-size: 16px;
  83.                         line-height: 1.6;
  84.                         color: #D1D5DB; /* Slightly darker gray for paragraph */
  85.                         margin-bottom: 30px;
  86.                     }
  87.                     .support-link {
  88.                         display: inline-block;
  89.                         background-color: #3B82F6; /* Blue for the button */
  90.                         color: #FFF;
  91.                         padding: 12px 25px;
  92.                         border-radius: 8px;
  93.                         text-decoration: none;
  94.                         font-weight: 600;
  95.                         transition: background-color 0.3s ease, transform 0.2s ease;
  96.                     }
  97.                     .support-link:hover {
  98.                         background-color: #2563EB; 
  99.                         transform: translateY(-2px);
  100.                     }
  101.                 </style>
  102.             </head>
  103.             <body>
  104.                 <div class="container">
  105.                     <svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
  106.                         <path stroke-linecap="round" stroke-linejoin="round" d="M18.364 18.364A9 9 0 0 0 5.636 5.636m12.728 12.728A9 9 0 0 1 5.636 5.636m12.728 12.728L5.636 5.636" />
  107.                         <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" />
  108.                     </svg>
  109.                     <h1>Ваш аккаунт заблокирован</h1>
  110.                     <p>Доступ к вашей учетной записи был ограничен. Если вы считаете, что это произошло по ошибке, пожалуйста, свяжитесь с нашей службой поддержки.</p>
  111.                     <a href="" class="support-link">Обратиться в поддержку</a>
  112.                 </div>
  113.             </body>
  114.             </html>
  115.             HTML;
  116.             return new Response($html403);
  117.         });
  118.         }
  119.     }
  120.     public static function getSubscribedEvents(): array
  121.     {
  122.         return [
  123.             KernelEvents::CONTROLLER => 'onKernelController',
  124.         ];
  125.     }
  126. }