<?php
namespace App\EventListener;
use Doctrine\DBAL\Connection;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Response;
class BanCheckSubscriber implements EventSubscriberInterface
{
private Connection $connection;
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
public function onKernelController(ControllerEvent $event): void
{
$request = $event->getRequest();
$session = $request->getSession();
$sid = $session->get('hash');
if (!$sid) {
return;
}
$user = $this->connection->fetchAssociative(
'SELECT * FROM users WHERE hash = ?', [$sid]
);
if ($user && ($user['ban'] ?? 0) == 1) {
$event->setController(function () {
$html = <<<HTML
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Аккаунт заблокирован</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
body {
background-color: #111827;
color: #E5E7EB;
font-family: 'Inter', sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
text-align: center;
}
.container {
background: #1F2937;
padding: 50px;
border-radius: 16px;
border: 1px solid #374151;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
max-width: 500px;
width: 90%;
animation: fadeIn 0.8s ease-out;
}
.icon {
width: 80px;
height: 80px;
margin: 0 auto 30px;
color: #EF4444; /* Red for the icon */
}
h1 {
font-size: 28px;
font-weight: 700;
margin: 0 0 15px;
color: #F9FAFB; /* White heading */
}
p {
font-size: 16px;
line-height: 1.6;
color: #D1D5DB; /* Slightly darker gray for paragraph */
margin-bottom: 30px;
}
.support-link {
display: inline-block;
background-color: #3B82F6; /* Blue for the button */
color: #FFF;
padding: 12px 25px;
border-radius: 8px;
text-decoration: none;
font-weight: 600;
transition: background-color 0.3s ease, transform 0.2s ease;
}
.support-link:hover {
background-color: #2563EB;
transform: translateY(-2px);
}
</style>
</head>
<body>
<div class="container">
<svg class="icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<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" />
<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" />
</svg>
<h1>Ваш аккаунт заблокирован</h1>
<p>Доступ к вашей учетной записи был ограничен. Если вы считаете, что это произошло по ошибке, пожалуйста, свяжитесь с нашей службой поддержки.</p>
<a href="" class="support-link">Обратиться в поддержку</a>
</div>
</body>
</html>
HTML;
return new Response($html, 403);
});
}
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => 'onKernelController',
];
}
}