You are here

public function BakeryUncrumbleForm::validateForm in Bakery Single Sign-On System 8.2

Validation for bakery_uncrumble form.

Overrides FormBase::validateForm

File

src/Forms/BakeryUncrumbleForm.php, line 161

Class

BakeryUncrumbleForm
Contribute form.

Namespace

Drupal\bakery\Forms

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  /*
   * We are ignoring blocked status on purpose.
   * The user is being repaired, not logged in.
   */

  /** @var \Drupal\user\UserInterface|false $account */
  $account = user_load_by_name($form_state
    ->getValue('name'));
  if (!($account && $account
    ->id()) || $this->passwordHasher
    ->check($form_state
    ->getValue('pass'), $account
    ->getPassword())) {
    $this
      ->logger('bakery')
      ->notice('Login attempt failed for %user while running uncrumble.', [
      '%user' => $form_state
        ->getValue('name'),
    ]);

    /*
     * Can't pretend that it was the "username or password"
     * so let's be helpful instead.
     */
    $form_state
      ->setErrorByName('pass', t('Sorry, unrecognized password. If you have forgotten your %site password, please <a href="@contact">contact the site administrator.</a>', [
      '%site' => $this
        ->configFactory()
        ->get('system.site')
        ->get('name'),
      '@contact' => $this
        ->configFactory()
        ->get('bakery.settings')
        ->get('bakery_master') . 'contact',
    ]));
  }
  else {
    $form_state
      ->setValue('bakery_uncrumble_account', $account);
  }
}