You are here

public function IpBanSetBanManager::iPBanDetermineAction in IP Ban 8

Determines action based on current user's ban setting.

Determine the action based on the user's ban setting. If the user is anonymous, this will be set via middleware; otherwise it will be set via an event subscriber.

Overrides IpBanSetBanInterface::iPBanDetermineAction

File

src/IpBanSetBanManager.php, line 79
Contains \Drupal\ip_ban\IpBanSetBanInterface.

Class

IpBanSetBanManager

Namespace

Drupal\ip_ban

Code

public function iPBanDetermineAction() {
  if ($this->banvalue == IP_BAN_READONLY) {
    $uri = \Drupal::service('path.current')
      ->getPath();
    if ($uri == 'user' || strpos($uri, 'user/') !== FALSE) {
      $path = \Drupal::config('ip_ban.settings')
        ->get('ip_ban_readonly_path');
      $response = new RedirectResponse($path);
      $response
        ->send();
      exit;
    }
  }
  if ($this->banvalue == IP_BAN_BANNED) {

    // Always allow access to the banned page.
    $complete_ban_path = \Drupal::config('ip_ban.settings')
      ->get('ip_ban_completeban_path');
    if (!empty($complete_ban_path) && \Drupal::service('path.current')
      ->getPath() != \Drupal::service('path_alias.manager')
      ->getPathByAlias($complete_ban_path)) {
      $response = new RedirectResponse($complete_ban_path);
      $response
        ->send();
    }
    else {
      \Drupal::messenger()
        ->addError(t(\Drupal::config('ip_ban.settings')
        ->get('ip_ban_completeban')));
    }
  }
}