You are here

function logintoboggan_form_user_pass_reset_alter in LoginToboggan 8

Same name and namespace in other branches
  1. 7 logintoboggan.module \logintoboggan_form_user_pass_reset_alter()

Implements hook_form_user_pass_reset_alter().

File

./logintoboggan.module, line 203
LoginToboggan module.

Code

function logintoboggan_form_user_pass_reset_alter(&$form, $form_state) {

  // Password resets count as validating an email address, so add trusted role.
  // We only want to run this code when user first hits the reset login form.
  $path = \Drupal::request()
    ->getpathInfo();
  $arg = explode('/', $path);
  if ($uid = (int) $arg[3]) {
    if ($account = user::load($uid)) {
      $roles = $account
        ->getRoles();
      $trusted_role = LogintobogganUtility::trustedRole();
      $got_trusted = in_array($trusted_role, $roles);
      if (!$got_trusted) {
        LogintobogganUtility::processValidation($account);
        \Drupal::messenger()
          ->addMessage(t('You have successfully validated your e-mail address.'), 'status');
      }
    }
  }
}