You are here

function simple_pass_reset_form_user_pass_alter in Simple Password Reset 7

Implements hook_form_FORM_ID_alter().

This is not about simplifying the text on the password reset form, but it's behavior. If a logged in user resets her password, she's sent a link via email. But will get access denied clicking that link, because she's already logged in! This hook will log her out when resetting password. This makes the password reset form behave more like the user edit form when a user changes their own password. (See where user_save() calls drupal_session_destroy_uid().)

File

./simple_pass_reset.module, line 191

Code

function simple_pass_reset_form_user_pass_alter(&$form, &$form_state) {

  // If the user views the password reset form while logged in...
  if (user_is_logged_in()) {
    drupal_set_title(t('Reset my password'));

    // Update the help text and button text to indicate that submitting the form
    // will log them out.
    $form['mail']['#markup'] = t('We will e-mail a password reset link for your account to %email. You will be logged out when you submit this form and should use that link to log back in.', array(
      '%email' => $form['name']['#value'],
    ));
    $form['actions']['submit']['#value'] = t('E-mail reset link and log out');

    // Add a form submit handler to log out upon submission.
    $form['#submit'][] = 'simple_pass_reset_form_user_pass_submit';
  }
}