You are here

LoginStatusCheck.php in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/user/src/Access/LoginStatusCheck.php

Namespace

Drupal\user\Access

File

core/modules/user/src/Access/LoginStatusCheck.php
View source
<?php

/**
 * @file
 * Contains \Drupal\user\Access\LoginStatusCheck.
 */
namespace Drupal\user\Access;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;

/**
 * Determines access to routes based on login status of current user.
 */
class LoginStatusCheck implements AccessInterface {

  /**
   * Checks access.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The currently logged in account.
   * @param \Symfony\Component\Routing\Route $route
   *   The route to check against.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(AccountInterface $account, Route $route) {
    $required_status = filter_var($route
      ->getRequirement('_user_is_logged_in'), FILTER_VALIDATE_BOOLEAN);
    $actual_status = $account
      ->isAuthenticated();
    return AccessResult::allowedIf($required_status === $actual_status)
      ->addCacheContexts([
      'user.roles:authenticated',
    ]);
  }

}

Classes

Namesort descending Description
LoginStatusCheck Determines access to routes based on login status of current user.