You are here

function prlp_form_user_pass_reset_alter in Password Reset Landing Page (PRLP) 6

Same name and namespace in other branches
  1. 8 prlp.module \prlp_form_user_pass_reset_alter()
  2. 7 prlp.module \prlp_form_user_pass_reset_alter()
  3. 7.x prlp.module \prlp_form_user_pass_reset_alter()

Alters the user password reset landing page.

Lets the user enter a new password directly on the landing page and adds a submit handler to save it.

File

./prlp.module, line 30
Password Reset Landing Page module.

Code

function prlp_form_user_pass_reset_alter(&$form, &$form_state) {
  @(list($formid, $form_form_state, $uid, $timestamp, $hashed_pass) = $form['#parameters']);
  if ($uid) {
    $form['#user'] = user_load($uid);

    // Inject the username/password change form into the current form.
    $edit = empty($form_state['values']) ? (array) $form['#user'] : $form_state['values'];
    $form = array_merge($form, _user_forms($edit, $form['#user'], 'account'));

    // ???
    $form['#user_category'] = 'account';

    // Hide certain fields in $form
    foreach ($form as $key => &$element) {
      if (in_array($key, prlp_get_hidden_fields())) {
        $element['#access'] = FALSE;
      }
    }

    // Hide certain fields in $form['account']
    foreach ($form['account'] as $key => &$element) {
      if (in_array($key, prlp_get_hidden_account_fields())) {
        $element['#access'] = FALSE;
      }
    }

    // Unset $form['#action'] so that the form doesn't get submitted to the
    // user profile edit page. Instead it gets submitted to self.
    unset($form['#action']);

    // Remove the part of the message that talks about changing password later, since they are changing it right here.
    if (!empty($form['message']['#value'])) {
      $form['message']['#value'] = str_replace('<p>Click on this button to log in to the site and change your password.</p>', '', $form['message']['#value']);
    }
    if (is_array($form['account']['pass']) && variable_get('prlp_password_required', 1)) {
      $form['account']['pass']['#required'] = TRUE;
    }

    // before sending the user to user profile edit form.
    $form['#submit'][] = 'prlp_user_pass_reset_submit';
  }
}