You are here

public function SecuresiteManager::showDialog in Secure Site 8

Overrides SecuresiteManagerInterface::showDialog

4 calls to SecuresiteManager::showDialog()
SecuresiteManager::denied in src/SecuresiteManager.php
Deny access to users who are not authorized to access secured pages.
SecuresiteManager::digestAuth in src/SecuresiteManager.php
Perform digest authentication.
SecuresiteManager::guestLogin in src/SecuresiteManager.php
SecuresiteManager::plainAuth in src/SecuresiteManager.php

File

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

Class

SecuresiteManager

Namespace

Drupal\securesite

Code

public function showDialog($type) {
  global $base_path, $language;
  $request = $this->request;
  $response = new Response();

  // Has the password reset form been submitted?

  //todo what is the use of the following if statement? why get the form and not display it?
  if (isset($_POST['form_id']) && $_POST['form_id'] == 'user_pass') {

    // Get form messages, but do not display form.
    \Drupal::formBuilder()
      ->getForm('securesite_user_pass');
    $content = '';
  }
  elseif (strpos(current_path(), 'user/reset/') === 0 || \Drupal::moduleHandler()
    ->moduleExists('locale') && $language->enabled && strpos(current_path(), $language->prefix . '/user/reset/') === 0) {
    $args = explode('/', current_path());
    if (\Drupal::moduleHandler()
      ->moduleExists('locale') && $language->enabled && $language->prefix != '') {

      // Remove the language argument.
      array_shift($args);
    }

    // The password reset function doesn't work well if it doesn't have all the
    // required parameters or if the UID parameter isn't valid
    if (count($args) < 5 || $this->entityManager
      ->getStorage('user')
      ->loadByProperties(array(
      'uid' => $args[2],
      'status' => 1,
    )) == FALSE) {
      $error = t('You have tried to use an invalid one-time log-in link.');
      $reset = \Drupal::config('securesite.settings')
        ->get('securesite_reset_form');
      if (empty($reset)) {
        drupal_set_message($error, 'error');
        $content = '';
      }
      else {
        $error .= ' ' . t('Please request a new one using the form below.');
        drupal_set_message($error, 'error');
        $content = \Drupal::formBuilder()
          ->getForm('securesite_user_pass');
      }
    }
  }
  elseif (!\Drupal::moduleHandler()
    ->moduleExists('openid') || $_GET['q'] != 'openid/authenticate') {

    // Display log-in dialog.
    switch ($type) {
      case SECURESITE_DIGEST:
        $realm = \Drupal::config('securesite.settings')
          ->get('securesite_realm');
        $header = $this
          ->_securesite_digest_validate($status, array(
          'realm' => $realm,
          'fakerealm' => $this
            ->getFakeRealm(),
        ));
        if (strpos($header, 'WWW-Authenticate') === 0) {
          $this->request->securesiteHeaders += array(
            'Status' => '401',
          );
        }
        else {
          $this->request->securesiteHeaders += array(
            'Status' => '401',
          );
          $this->request->securesiteHeaders += array(
            $header['name'] => $header['value'],
          );
        }
        break;
      case SECURESITE_BASIC:
        $this->request->securesiteHeaders += array(
          'Status' => '401',
        );
        $this->request->securesiteHeaders += array(
          'WWW-Authenticate' => 'Basic realm="' . $this
            ->getFakeRealm() . '"',
        );
      case SECURESITE_FORM:
        $this->request->securesiteHeaders += array(
          'Status' => '200',
        );
        break;
    }

    // Form authentication doesn't work for cron, so allow cron.php to run
    // without authenticating when no other authentication type is enabled.
    if ((request_uri() != $base_path . 'cron.php' || \Drupal::config('securesite.settings')
      ->get('securesite_type') != array(
      SECURESITE_FORM,
    )) && in_array(SECURESITE_FORM, \Drupal::config('securesite.settings')
      ->get('securesite_type'))) {

      //todo fix next line

      //drupal_set_title(t('Authentication required'));
      $content = $this
        ->dialogPage();
    }
  }
  if (isset($content)) {

    // Theme and display output
    $html = _theme('securesite_page', array(
      'content' => $content,
    ));
    $response
      ->setContent($html);
    $response->headers
      ->set('Content-Type', 'text/html');
    $response
      ->send();
    exit;
  }
}