You are here

public function SecuresiteManager::guestLogin in Secure Site 8

2 calls to SecuresiteManager::guestLogin()
SecuresiteManager::digestAuth in src/SecuresiteManager.php
Perform digest authentication.
SecuresiteManager::plainAuth in src/SecuresiteManager.php

File

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

Class

SecuresiteManager

Namespace

Drupal\securesite

Code

public function guestLogin($edit) {
  $config = \Drupal::config('securesite.settings');
  $guest_name = $config
    ->get('securesite_guest_name');
  $guest_pass = $config
    ->get('securesite_guest_pass');
  $anonymous_user = new AnonymousUserSession();

  // Check anonymous user permission and credentials.
  if ($anonymous_user
    ->hasPermission('access secured pages') && (empty($guest_name) || $edit['name'] == $guest_name) && (empty($guest_pass) || $edit['pass'] == $guest_pass)) {

    // Unset the session variable set by securesite_denied().
    if (isset($_SESSION['securesite_denied'])) {
      unset($_SESSION['securesite_denied']);
    }

    // Mark this session to prevent re-login (note: guests can't log out).
    $_SESSION['securesite_guest'] = $edit['name'];
    $_SESSION['securesite_login'] = TRUE;

    // Prevent a 403 error by redirecting off the logout page.
    if (current_path() == 'user/logout') {
      $response = new RedirectResponse('/');
      $response
        ->send();
    }
  }
  else {
    if ((empty($guest_name) || $edit['name'] == $guest_name) && (empty($guest_pass) || $edit['pass'] == $guest_pass)) {
      \Drupal::logger('user')
        ->notice('Log-in attempt failed for <em>anonymous</em> user.');
      $this
        ->denied(t('Anonymous users are not allowed to log in to secured pages.'));
    }
    else {
      \Drupal::logger('user')
        ->notice('Log-in attempt failed for %user.', array(
        '%user' => $edit['name'],
      ));
      drupal_set_message(t('Unrecognized user name and/or password.'), 'error');
      $this
        ->showDialog($this
        ->getType());
    }
  }
}