You are here

public function AutoLoginUrlMainController::login in Auto Login URL 2.x

Same name and namespace in other branches
  1. 8 src/Controller/AutoLoginUrlMainController.php \Drupal\auto_login_url\Controller\AutoLoginUrlMainController::login()

Auto login method.

Parameters

int $uid: The ID of the user.

string $hash: The hash string on the URL.

1 string reference to 'AutoLoginUrlMainController::login'
auto_login_url.routing.yml in ./auto_login_url.routing.yml
auto_login_url.routing.yml

File

src/Controller/AutoLoginUrlMainController.php, line 24

Class

AutoLoginUrlMainController
Class AutoLoginUrlMainController.

Namespace

Drupal\auto_login_url\Controller

Code

public function login($uid, $hash) {

  // Disable page cache.
  \Drupal::service('page_cache_kill_switch')
    ->trigger();

  // Check for flood events.
  if (\Drupal::service('auto_login_url.general')
    ->checkFlood()) {
    $this
      ->messenger()
      ->addError($this
      ->t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later.'));
    throw new AccessDeniedHttpException();
  }
  $destination = \Drupal::service('auto_login_url.login')
    ->login($uid, $hash);
  if ($destination) {
    return new RedirectResponse($destination);
  }
  else {

    // Register flood event.
    \Drupal::service('auto_login_url.general')
      ->registerFlood($hash);
    throw new AccessDeniedHttpException();
  }
}