edgar.dueñas
Enviado por edgar.dueñas el Mié, 11/05/2016 - 17:00

Crea un bloque drupal 7 para cambiar la contraseña y este se puede colocar en cualquier parte del sitio como un bloque normal.

http://drupal.stackexchange.com/questions/32722/how-can-i-display-a-change-password-form-on-its-own

No pude encontrar nada por ahí y me pareció algo útil, así que aquí hay un pequeño módulo que proporciona un bloque con un formulario de cambio de contraseña: Archivo: change_password.info

name = Change Password description = Proporciona un bloque que contiene un formulario para que el usuario actual cambie su contraseña. core = 7.x

Archivo: change_password.module

<?php
 
/**
* Implements hook_block_info().
*/
function change_password_block_info() {
  return array(
    'change_password_form' => array(
      'info' => t('Change Password Form')
    )
  );
}
 
/**
* Implements hook_block_view().
*/
function change_password_block_view($delta = '') {
  $block = array();
  // Only show the block for a logged-in user.
  if ($delta == 'change_password_form' && user_is_logged_in()) {
    $block['subject'] = t('Change Password');
    $block['content'] = drupal_get_form('change_password_form');
  }
  return $block;
}
 
/**
* Password change form.
*/
function change_password_form($form, &$form_state) {
  // Sanity check
  if (user_is_anonymous()) {
    return $form; // Or drupal_access_denied()?
  }
 
  // Get the currently logged in user object.
  $form['#account'] = $GLOBALS['user'];
 
  // Textfield cor current password confirmation.
  $form['current_pass'] = array(
    '#type' => 'password',
    '#title' => t('Current password'),
    '#size' => 25,
    '#required' => TRUE
  );
 
  // Password confirm field.
  $form['account']['pass'] = array(
    '#type' => 'password_confirm',
    '#size' => 25,
    '#title' => t('New Password'),
    '#required' => TRUE
  );
 
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
  );
 
  return $form;
}
 
/**
* Validate handler for change_password_form().
*/
function change_password_form_validate(&$form, &$form_state) {  
  // Make sure the password functions are present.
  require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
 
  // Make sure the provided current password is valid for this account.
  if (!user_check_password($form_state['values']['current_pass'], $form['#account'])) {
    form_set_error('current_pass', t('The current password you provided is incorrect.'));
  }
}
 
/**
* Submit handler for change_password_form().
*/
function change_password_form_submit(&$form, &$form_state) {
  // Set up the edit array to pass to user_save()
  $edit = array('pass' => $form_state['values']['pass']);
 
  // Save the account with the new password.
  user_save($form['#account'], $edit);
 
  // Inform the user.
  drupal_set_message(t('Your password has been changed.'));
}