function UserFloodControl::isAllowed

Same name in other branches
  1. 10 core/modules/user/src/UserFloodControl.php \Drupal\user\UserFloodControl::isAllowed()
  2. 11.x core/modules/user/src/UserFloodControl.php \Drupal\user\UserFloodControl::isAllowed()

File

core/modules/user/src/UserFloodControl.php, line 58

Class

UserFloodControl
User Flood Control service.

Namespace

Drupal\user

Code

public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) {
    if ($this->flood
        ->isAllowed($name, $threshold, $window, $identifier)) {
        return TRUE;
    }
    // Register flood control blocked login event.
    $event_map['user.failed_login_ip'] = UserEvents::FLOOD_BLOCKED_IP;
    $event_map['user.failed_login_user'] = UserEvents::FLOOD_BLOCKED_USER;
    $event_map['user.http_login'] = UserEvents::FLOOD_BLOCKED_USER;
    if (isset($event_map[$name])) {
        if (empty($identifier)) {
            $identifier = $this->requestStack
                ->getCurrentRequest()
                ->getClientIp();
        }
        $event = new UserFloodEvent($name, $threshold, $window, $identifier);
        $this->eventDispatcher
            ->dispatch($event, $event_map[$name]);
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.