You are here

public function SessionLimit::getUserMaxSessions in Session Limit 8

Same name and namespace in other branches
  1. 2.x src/Services/SessionLimit.php \Drupal\session_limit\Services\SessionLimit::getUserMaxSessions()

Get the maximum sessions allowed for a specific user.

Parameters

\Drupal\Core\Session\AccountInterface $account:

Return value

int The number of allowed sessions. A value less than 1 means unlimited.

2 calls to SessionLimit::getUserMaxSessions()
SessionLimit::getMessage in src/Services/SessionLimit.php
Get the logged out message for the given user.
SessionLimit::onKernelRequest in src/Services/SessionLimit.php
Event listener, on executing a Kernel request.

File

src/Services/SessionLimit.php, line 428

Class

SessionLimit

Namespace

Drupal\session_limit\Services

Code

public function getUserMaxSessions(AccountInterface $account) {
  $limit = $this->configFactory
    ->get('session_limit.settings')
    ->get('session_limit_max');
  $role_limits = $this->configFactory
    ->get('session_limit.settings')
    ->get('session_limit_roles');
  foreach ($account
    ->getRoles() as $rid) {
    if (!empty($role_limits[$rid])) {
      if ($role_limits[$rid] == self::USER_UNLIMITED_SESSIONS) {

        // If they have an unlimited role then just return the unlimited value;
        return self::USER_UNLIMITED_SESSIONS;
      }

      // Otherwise, the user gets the largest limit available.
      $limit = max($limit, $role_limits[$rid]);
    }
  }

  // @todo reinstate per user limits.
  return $limit;
}