You are here

function password_policy_password_tab in Password Policy 7

Same name and namespace in other branches
  1. 6 contrib/password_tab/password_policy_password_tab.pages.inc \password_policy_password_tab()

Password change form.

4 string references to 'password_policy_password_tab'
PasswordPolicyPasswordTabTestCase::setUp in contrib/password_tab/password_policy_password_tab.test
Set up the test.
password_policy_form_alter in ./password_policy.module
Implements hook_form_alter().
password_policy_password_tab_menu in contrib/password_tab/password_policy_password_tab.module
Implements hook_menu().
_password_policy_get_password_edit_paths_for_user in ./password_policy.module
Gets password edit paths for the given user.

File

contrib/password_tab/password_policy_password_tab.pages.inc, line 11
The password policy password tab page callbacks.

Code

function password_policy_password_tab($form, &$form_state, $account) {
  global $user;

  // During initial form build, add the entity to the form state for use during
  // form building and processing. During a rebuild, use what is in the form
  // state.
  if (!isset($form_state['user'])) {
    $form_state['user'] = $account;
  }
  else {
    $account = $form_state['user'];
  }
  if ($user->uid == $account->uid) {

    // To skip the current password field, the user must have logged in via a
    // one-time link and have the token in the URL.
    $pass_reset = isset($_SESSION['pass_reset_' . $account->uid]) && isset($_GET['pass-reset-token']) && $_GET['pass-reset-token'] == $_SESSION['pass_reset_' . $account->uid];
    $protected_values = array();
    $current_pass_description = '';

    // The user may only change their own password without their current
    // password if they logged in via a one-time login link.
    if (!$pass_reset) {
      $protected_values['mail'] = t('E-mail address');
      $protected_values['pass'] = t('Password');
      $request_new = l(t('Request new password'), 'user/password', array(
        'attributes' => array(
          'title' => t('Request new password via e-mail.'),
        ),
      ));
      $current_pass_description = t('Enter your current password to change the %pass. !request_new.', array(
        '%pass' => $protected_values['pass'],
        '!request_new' => $request_new,
      ));
    }

    // The user must enter their current password to change to a new one.
    if (isset($protected_values['pass'])) {
      $form['account']['current_pass_required_values'] = array(
        '#type' => 'value',
        '#value' => array(
          'pass' => $protected_values['pass'],
        ),
      );
      $form['account']['current_pass'] = array(
        '#type' => 'password',
        '#title' => t('Current password'),
        '#size' => 25,
        '#access' => !empty($protected_values),
        '#description' => $current_pass_description,
        '#weight' => -5,
        '#attributes' => array(
          'autocomplete' => 'off',
        ),
      );
      $form['#validate'][] = 'user_validate_current_pass';
    }
  }
  $form['account']['pass'] = array(
    '#type' => 'password_confirm',
    '#size' => 25,
    '#required' => TRUE,
    '#description' => t('To change the current user password, enter the new password in both fields.'),
  );

  // @TODO Remove this as it supports a D6-style of interacting with a user form
  // In the future, this data should be stored in $form_state.
  $form['#uid'] = $account->uid;
  $form['#user'] = $account;
  $form['_account'] = array(
    '#type' => 'value',
    '#value' => $account,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}