You are here

public function LegalLogin::validateForm in Legal 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/LegalLogin.php \Drupal\legal\Form\LegalLogin::validateForm()

Form validation handler.

Parameters

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

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

Overrides FormBase::validateForm

File

src/Form/LegalLogin.php, line 162

Class

LegalLogin
After login display new T&Cs to user and require that they are agreed to.

Namespace

Drupal\legal\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $token = $form_state
    ->getValue('token');
  $uid = $form_state
    ->getValue('uid');
  $account = User::load($uid);
  $this->user = $account;
  $last_login = $account
    ->get('login')->value;
  $password = $account
    ->get('pass')->value;
  $data = $last_login . $uid . $password;
  $hash = Crypt::hmacBase64($data, $token);
  if ($hash != $form_state
    ->getValue('hash')) {
    $form_state
      ->setErrorByName('legal_accept', $this
      ->t('User ID cannot be identified.'));
    legal_deny_with_redirect();
  }
}