You are here

function _openid_connect_user_pass_form_validate in OpenID Connect / OAuth client 2.x

Same name and namespace in other branches
  1. 8 openid_connect.module \_openid_connect_user_pass_form_validate()
  2. 7 openid_connect.module \_openid_connect_user_pass_form_validate()

Validate user password reset form on existing connections with openid.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 string reference to '_openid_connect_user_pass_form_validate'
openid_connect_form_user_pass_alter in ./openid_connect.module
Implements hook_form_FORM_ID_alter().

File

./openid_connect.module, line 138
Hook implementations of the OpenID Connect module.

Code

function _openid_connect_user_pass_form_validate(array &$form, FormStateInterface $form_state) {
  $name = $form_state
    ->getValue('name');
  if (empty($name)) {
    return;
  }

  // Try to load by email.
  $user = user_load_by_mail($name);
  if (empty($user)) {

    // No success, try to load by name.
    $user = user_load_by_name($name);
  }
  if (!empty($user) && !\Drupal::service('openid_connect.openid_connect')
    ->hasSetPasswordAccess($user)) {
    $form_state
      ->setErrorByName('name', t('%name is connected to an external authentication system.', [
      '%name' => $name,
    ]));
  }
}