UserFloodSubscriber.php in Drupal 10
File
core/modules/user/src/EventSubscriber/UserFloodSubscriber.php
View source
<?php
namespace Drupal\user\EventSubscriber;
use Drupal\user\Event\UserEvents;
use Drupal\user\Event\UserFloodEvent;
use Drupal\Core\Site\Settings;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Psr\Log\LoggerInterface;
class UserFloodSubscriber implements EventSubscriberInterface {
protected $logger;
public function __construct(LoggerInterface $logger = NULL) {
$this->logger = $logger;
}
public static function getSubscribedEvents() : array {
$events[UserEvents::FLOOD_BLOCKED_USER][] = [
'blockedUser',
];
$events[UserEvents::FLOOD_BLOCKED_IP][] = [
'blockedIp',
];
return $events;
}
public function blockedUser(UserFloodEvent $floodEvent) {
if (Settings::get('log_user_flood', TRUE)) {
$uid = $floodEvent
->getUid();
if ($floodEvent
->hasIp()) {
$ip = $floodEvent
->getIp();
$this->logger
->notice('Flood control blocked login attempt for uid %uid from %ip', [
'%uid' => $uid,
'%ip' => $ip,
]);
return;
}
$this->logger
->notice('Flood control blocked login attempt for uid %uid', [
'%uid' => $uid,
]);
}
}
public function blockedIp(UserFloodEvent $floodEvent) {
if (Settings::get('log_user_flood', TRUE)) {
$this->logger
->notice('Flood control blocked login attempt from %ip', [
'%ip' => $floodEvent
->getIp(),
]);
}
}
}