You are here

password_policy_password_tab.module in Password Policy 7

Same filename and directory in other branches
  1. 6 contrib/password_tab/password_policy_password_tab.module

Adds a separate tab to change password.

File

contrib/password_tab/password_policy_password_tab.module
View source
<?php

/**
 * @file
 * Adds a separate tab to change password.
 */

/**
 * Implements hook_help().
 */
function password_policy_password_tab_help($path, $arg) {
  switch ($path) {
    case 'admin/help#password_policy_password_tab':
      return '<p>' . t('Adds a separate tab for the user to change their password.  When enabled, the password change fields are removed from the user edit tab.') . '</p>';
  }
}

/**
 * Implements hook_menu().
 */
function password_policy_password_tab_menu() {
  $items = array();
  $items['user/%user/password'] = array(
    'title' => 'Password',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'password_policy_password_tab',
      1,
    ),
    'access callback' => 'user_edit_access',
    'access arguments' => array(
      1,
    ),
    'type' => MENU_LOCAL_TASK,
    'file' => 'password_policy_password_tab.pages.inc',
  );
  $items['admin/config/people/password_policy/password_tab'] = array(
    'title' => 'Password tab',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'password_policy_password_tab_admin_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'password_policy_password_tab.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  return $items;
}

/**
 * Implements hook_admin_paths().
 */
function password_policy_password_tab_admin_paths() {
  $paths = array(
    'user/*/password' => TRUE,
  );
  return $paths;
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function password_policy_password_tab_form_user_profile_form_alter(&$form, &$form_state) {
  if (isset($form['account']['current_pass_required_values']['#value']['pass'])) {
    $form['account']['current_pass']['#description'] = str_replace(' or <em class="placeholder">Password</em>', '', $form['account']['current_pass']['#description']);
    unset($form['account']['current_pass_required_values']['#value']['pass']);
  }

  // Hide core password field from user edit form.
  unset($form['account']['pass']);
}

/**
 * Implements hook_drupal_goto_alter().
 */
function password_policy_password_tab_drupal_goto_alter(&$path, &$options) {
  global $user;
  if ($user->uid && $path == 'user/' . $user->uid . '/edit' && isset($options['query']['pass-reset-token'])) {
    $path = 'user/' . $user->uid . '/password';
  }
}