Here is a brief explanation for doing a little hack to switch from administrator role to any other user in Drupal 6
Hack en Drupal 6 para cambiar de login desde Administrador hasta cualquier otro usuario

in my WEBSITE.module
in my function WEBSITE_module_menu()

$items['admin/user/user/switch'] = array(
      'title'            => 'Cambiar de usuario',
      'access callback'  => 'user_access',
      'page callback'    => 'WEBSITE_module_switch',      
      'access arguments' => array('administer rules'),
      'type'             => MENU_NORMAL_ITEM
    );

afterwards, i have these functions:

function WEBSITE_module_switch_form(){
  $form['nombre'] = array(
    '#type'    => 'textfield',
    '#title'   => t('Nombre de usuario'),
    '#size'    => 22
  );
  $form['submit'] = array(
    '#type'  => 'submit',
    '#value' => t('Cambiar a este usuario'),
  );
  return $form;
}

function WEBSITE_module_switch(){
  return drupal_get_form(WEBSITE_module_switch_form);
}

function WEBSITE_module_switch_form_submit($form, &$form_state){
  $profile = user_load(array('mail'=>$form['nombre']['#value']));
  if (is_numeric($profile->uid)){
    drupal_set_message('ahora eres' . $profile->name);
    drupal_goto('/devel/switch/'. $profile->name);
  }else{
    drupal_set_message('el usuario no existe', 'warning');
    drupal_goto('/admin/user/user/switch');
  }
}

et voilà!
clicking in «User administration/Users/Switch User» we can switch to any user introducin his email in the textbox :)

Post new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Twitter icon
Facebook icon
LinkedIn icon