You are here

function logintoboggan_form_user_pass_reset_alter in LoginToboggan 7

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

Implement hook_form_user_pass_reset_alter().

Related topics

File

./logintoboggan.module, line 292
LoginToboggan module

Code

function logintoboggan_form_user_pass_reset_alter(&$form, &$form_state) {
  $form_args = $form_state['build_info']['args'];

  // The signature for user_pass_reset (after form and form_state) is:
  // $uid, $timestamp, $hashed_pass, $action = NULL
  $uid = $form_args[0];
  $action = isset($form_args[3]) ? $form_args[3] : NULL;

  // Make sure this isn't a rebuild of the password reset form.
  // Drupal invokes form builders during submit, so avoid acting twice.
  $is_first_form_build = empty($action) && empty($form_state['input']);

  // Password resets count as validating an email address, so remove the user
  // from the pre-auth role if they are still in it. We only want to run this
  // code when the user first hits the reset login form.
  if ($is_first_form_build && ($account = user_load($uid))) {
    $id = logintoboggan_validating_id();
    $in_pre_auth_role = $id != DRUPAL_AUTHENTICATED_RID && in_array($id, array_keys($account->roles));
    if ($in_pre_auth_role) {
      _logintoboggan_process_validation($account);
    }

    // Display a success message either on first log-in, or if we just promoted
    // the user out of pre-auth state.
    if ($account->login == 0 || $in_pre_auth_role) {
      drupal_set_message(t('You have successfully validated your e-mail address.'));
    }
  }
}