You are here

private function ServiceController::getLoginErrorMessage in CAS 2.x

Same name and namespace in other branches
  1. 8 src/Controller/ServiceController.php \Drupal\cas\Controller\ServiceController::getLoginErrorMessage()

Get the error message to display when there is a login exception.

Parameters

\Drupal\cas\Exception\CasLoginException $e: The login exception.

Return value

array|\Drupal\Core\StringTranslation\TranslatableMarkup|string The error message.

1 call to ServiceController::getLoginErrorMessage()
ServiceController::handle in src/Controller/ServiceController.php
Main point of communication between CAS server and the Drupal site.

File

src/Controller/ServiceController.php, line 345

Class

ServiceController
Controller used when redirect back from CAS authentication.

Namespace

Drupal\cas\Controller

Code

private function getLoginErrorMessage(CasLoginException $e) {
  $code = $e
    ->getCode();
  switch ($code) {
    case CasLoginException::NO_LOCAL_ACCOUNT:
      $msgKey = 'message_no_local_account';
      break;
    case CasLoginException::SUBSCRIBER_DENIED_REG:

      // If a subscriber has denied the registration by setting a custom
      // message, use that message and exit here.
      $message = $e
        ->getSubscriberCancelReason();
      if ($message) {
        return $message;
      }
      $msgKey = 'message_subscriber_denied_reg';
      break;
    case CasLoginException::ACCOUNT_BLOCKED:
      $msgKey = 'message_account_blocked';
      break;
    case CasLoginException::SUBSCRIBER_DENIED_LOGIN:

      // If a subscriber has denied the login by setting a custom message, use
      // that message and exit here.
      $message = $e
        ->getSubscriberCancelReason();
      if ($message) {
        return $message;
      }
      $msgKey = 'message_subscriber_denied_login';
      break;
    case CasLoginException::ATTRIBUTE_PARSING_ERROR:

      // Re-use the normal validation error message.
      $msgKey = 'message_validation_failure';
      break;
    case CasLoginException::USERNAME_ALREADY_EXISTS:
      $msgKey = 'message_username_already_exists';
      break;
  }
  if (!empty($msgKey)) {
    $message = $this->casHelper
      ->getMessage('error_handling.' . $msgKey);
    if ($message) {
      return $message;
    }
  }
  return $this
    ->t('There was a problem logging in. Please contact a site administrator.');
}