You are here

protected function ImageHotspotsController::accessCallback in Image Hotspots 8

Check if user allowed to do actions with hotspots right now.

Return value

bool Returns true of false when access is requested.

4 calls to ImageHotspotsController::accessCallback()
ImageHotspotsController::createAction in src/Controller/ImageHotspotsController.php
Creates hotspot with values from request data.
ImageHotspotsController::deleteAction in src/Controller/ImageHotspotsController.php
Deletes hotspot with $hid.
ImageHotspotsController::translateAction in src/Controller/ImageHotspotsController.php
Translate hotspot with $hid.
ImageHotspotsController::updateAction in src/Controller/ImageHotspotsController.php
Update hotspot with $hid.

File

src/Controller/ImageHotspotsController.php, line 205

Class

ImageHotspotsController
Class ImageHotspotsController.

Namespace

Drupal\image_hotspots\Controller

Code

protected function accessCallback() {
  $flood = \Drupal::flood();
  $name = 'image_hotspots.action';
  $ip = \Drupal::request()
    ->getClientIp();

  // Anonymous can work with hotspots every 20 seconds.
  if ($this
    ->currentUser()
    ->isAnonymous()) {
    $count = 1;
    $window = 20;
    if ($flood
      ->isAllowed($name, $count, $window, $ip)) {
      $flood
        ->register($name, $window, $ip);
      return TRUE;
    }
    else {
      return FALSE;
    }
  }
  else {
    $count = 5;
    $window = 10;
    if ($flood
      ->isAllowed($name, $count, $window, $ip)) {
      $flood
        ->register($name, $window, $ip);
      return TRUE;
    }
    else {
      return FALSE;
    }
  }
}