You are here

public function SecuresiteManager::boot in Secure Site 8

Parameters

int $type: type of the authentication mechanism

Overrides SecuresiteManagerInterface::boot

File

src/SecuresiteManager.php, line 121
Contains \Drupal\securesite\SecuresiteManager.

Class

SecuresiteManager

Namespace

Drupal\securesite

Code

public function boot($type) {
  $currentUser = \Drupal::currentUser();
  $request = $this->request;
  switch ($type) {
    case SECURESITE_DIGEST:
      $edit = $this
        ->parseDirectives($_SERVER['PHP_AUTH_DIGEST']);
      $edit['name'] = $edit['username'];
      $edit['pass'] = NULL;
      $function = 'digestAuth';
      break;
    case SECURESITE_BASIC:
      $edit['name'] = $request->headers
        ->get('PHP_AUTH_USER', '');
      $edit['pass'] = $request->headers
        ->get('PHP_AUTH_PW', '');
      $function = 'plainAuth';
      break;
    case SECURESITE_FORM:

      //todo check if openid works
      if (!empty($_POST['openid_identifier'])) {
        openid_begin($_POST['openid_identifier'], $_POST['openid.return_to']);
      }
      $edit = array(
        'name' => $request->request
          ->get('name'),
        'pass' => $request->request
          ->get('pass'),
      );
      $function = 'plainAuth';
      break;
  }

  // Are credentials different from current user?
  $differentUser = $currentUser
    ->getUsername() == \Drupal::config('user.settings')
    ->get('anonymous') || $edit['name'] !== $currentUser
    ->getUsername();
  $notGuestLogin = !isset($_SESSION['securesite_guest']) || $edit['name'] !== $_SESSION['securesite_guest'];
  if ($differentUser && $notGuestLogin) {
    $this
      ->{$function}($edit);
  }
}