Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions login_one_time.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/LoginOneTimeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down