$OpenBSD: patch-masquerade_module,v 1.3 2008/10/25 17:04:48 espie Exp $ --- masquerade.module.orig Thu Sep 25 14:09:34 2008 +++ masquerade.module Sat Oct 25 19:01:27 2008 @@ -267,14 +267,23 @@ function masquerade_block_1($record) { * Masquerade block form validation. Implementation of hook_validate(). */ function masquerade_block_1_validate($form_id, $form_value) { - if ($form_value['masquerade_user_field'] == '') { + $name = $form_value['masquerade_user_field']; + + if ($name == '') { form_set_error('masquerade_user_field', t('You cannot masquerade as %anonymous!', array('%anonymous' => variable_get('anonymous', 'Anonymous')))); } if ($GLOBALS['masquerading']) { form_set_error('masquerade_user_field', t('You are already masquerading!')); } global $user; - $masq_user = user_load(array('name' => $form_value['masquerade_user_field'])); + + if (module_exists('alt_login')) { + $alt_login = db_fetch_object(db_query("SELECT u.name FROM {users} u INNER JOIN {alt_login} al ON u.uid = al.uid WHERE al.alt_login = '%s'", $name)); + if ($alt_login->name) { + $name = $alt_login->name; + } + } + $masq_user = user_load(array('name' => $name)); if (!$masq_user) { form_set_error('masquerade_user_field', t('User %masq_as does not exist. Please enter a valid username.', array('%masq_as' => $form_value['masquerade_user_field']))); } @@ -290,15 +299,16 @@ function masquerade_block_1_validate($form_id, $form_v * Masquerade block form submission. Implementation of hook_submit(). */ function masquerade_block_1_submit($form_id, $form_values) { - $masq_user = user_load(array('name' => $form_values['masquerade_user_field'])); + $name = $form_values['masquerade_user_field']; - if (module_exists('alt_login')) { // alt_login.module integration patch by espie. + if (module_exists('alt_login')) { $alt_login = db_fetch_object(db_query("SELECT u.name FROM {users} u INNER JOIN {alt_login} al ON u.uid = al.uid WHERE al.alt_login = '%s'", $name)); if ($alt_login->name) { - $masq_user = user_load(array('name' => $alt_login->name)); + $name = $alt_login->name; } } + $masq_user = user_load(array('name' => $name)); masquerade_switch_user($masq_user->uid); } @@ -310,6 +320,12 @@ function masquerade_autocomplete($string) { $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); + } + if (module_exists('alt_login')) { + $result = db_query_range("SELECT alt_login FROM {alt_login} WHERE LOWER(alt_login) LIKE LOWER('%s%%')", $string, 0, 10); + while ($user = db_fetch_object($result)) { + $matches[$user->alt_login] = check_plain($user->alt_login); + } } print drupal_to_js($matches); exit();