diff --git a/login_one_time.module b/login_one_time.module index ca2e254..50f1c23 100644 --- a/login_one_time.module +++ b/login_one_time.module @@ -133,18 +133,22 @@ function login_one_time_form_user_form_alter(&$form, FormStateInterface $form_st // Remove the current password field from user profile edit form // and disable validation. if (\Drupal::config('login_one_time.settings') - ->get('ignore_current_pass') && isset($_SESSION['ignore_current_pass']) && $_SESSION['ignore_current_pass'] + ->get('user_ignore_current_pass') && isset($_SESSION['user_ignore_current_pass']) && $_SESSION['user_ignore_current_pass'] ) { - $key = array_search('user_validate_current_pass', $form['#validate']); - - if ($key !== FALSE) { - unset($form['#validate'][$key]); - } - + $form['#validate'][]='user_do_not_validate_pass'; $form['account']['current_pass']['#access'] = FALSE; } } - +function user_do_not_validate_pass($form, FormStateInterface &$form_state){ + $errors=$form_state->getErrors(); + if (isset($errors['pass'])){ + unset($errors['pass']); + foreach ($errors as $key=>$msg) { + $form_state->setErrorByName($key,$msg); + } + } + +} /** * Implements hook_tokens(). */ diff --git a/src/Controller/LoginOneTimeController.php b/src/Controller/LoginOneTimeController.php index 2362f85..cc8c7d4 100644 --- a/src/Controller/LoginOneTimeController.php +++ b/src/Controller/LoginOneTimeController.php @@ -81,7 +81,7 @@ public function page($uid, $timestamp, $hashed_pass) { \Drupal::moduleHandler()->invokeAll('login_one_time_used', [$user]); // Add a session variable indicating whether the ignore current password field setting is enabled. - $_SESSION['ignore_current_pass'] = \Drupal::config('login_one_time.settings')->get('ignore_current_pass'); + $_SESSION['user_ignore_current_pass'] = \Drupal::config('login_one_time.settings')->get('user_ignore_current_pass'); drupal_set_message(t('You have just used your one-time login link.')); return new RedirectResponse($action); }