You are here

function login_user_block_ip in Login Security 8

Same name and namespace in other branches
  1. 5 login_security.module \login_user_block_ip()
  2. 6 login_security.module \login_user_block_ip()
  3. 7 login_security.module \login_user_block_ip()
  4. 2.x login_security.module \login_user_block_ip()

Create a Deny entry for the IP address.

If IP address is not especified then block current IP.

1 call to login_user_block_ip()
login_security_validate in ./login_security.module
Implements hook_validate().

File

./login_security.module, line 347
Login Security module hooks.

Code

function login_user_block_ip($variables, FormStateInterface $form_state) {

  // There is no need to check if the host has been banned, we can't get here
  // twice.
  $conf = \Drupal::config('login_security.settings');
  $ip = $variables['@ip'];
  \Drupal::database()
    ->merge('ban_ip')
    ->key([
    'ip' => $ip,
  ])
    ->fields([
    'ip' => $ip,
  ])
    ->execute();
  \Drupal::logger('login_security')
    ->notice('Banned IP address @ip due to security configuration.', $variables);
  $form_state
    ->setErrorByName('void', SafeMarkup::format($conf
    ->get('host_hard_banned'), $variables));
}