You are here

function _cas_validate_user_pass_form in CAS 8

Same name and namespace in other branches
  1. 2.x cas.module \_cas_validate_user_pass_form()

Custom form validator for the password reset form.

1 string reference to '_cas_validate_user_pass_form'
cas_form_user_pass_alter in ./cas.module
Implements hook_form_FORM_ID_alter().

File

./cas.module, line 109
Provides CAS authentication for Drupal.

Code

function _cas_validate_user_pass_form(array &$form, FormStateInterface $form_state) {

  // If the previous validation succeeded, the 'account' value is not NULL.
  // @see \Drupal\user\Form\UserPasswordForm::validateForm()
  $account = $form_state
    ->getValue('account');
  if ($account) {

    /** @var \Drupal\cas\Service\CasUserManager $cas_user_manager */
    $cas_user_manager = \Drupal::service('cas.user_manager');

    // Check if this user account is associated with CAS and set an error if so.
    if ($cas_user_manager
      ->getCasUsernameForAccount($account
      ->id())) {
      $form_state
        ->setErrorByName('name', \Drupal::service('cas.helper')
        ->getMessage('error_handling.message_restrict_password_management'));
    }
  }
}