diff --git a/aes.module b/aes.module index c28c99b..60c6769 100644 --- a/aes.module +++ b/aes.module @@ -35,6 +35,15 @@ function aes_menu() { 'type' => MENU_LOCAL_TASK, ); + $items['aes_get_password_callback/%'] = array( + 'title' => 'User password', + 'page callback' => 'aes_ajax_callback', + 'page arguments' => array(1), + 'access callback' => 'aes_show_password_page', + 'access arguments' => array('view passwords', 1), + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -403,11 +412,11 @@ function aes_user_view($account, $view_mode, $langcode) { if (user_access('view passwords') && (variable_get("aes_viewing_method", "page") == "collapsible" || variable_get("aes_viewing_method", "page") == "both") && variable_get("aes_convert", FALSE)) { if (aes_password_exists($account->uid)) { - $password_form = drupal_get_form('aes_view_password_form', aes_get_password($account->uid, TRUE)); + $password = aes_get_password($account->uid, TRUE); $account->content['info']['aes_password'] = array( '#type' => 'user_profile_item', '#title' => t('AES Encryption'), - '#markup' => drupal_render($password_form), + '#markup' => aes_password_view($account->uid), ); } else { @@ -421,6 +430,32 @@ function aes_user_view($account, $view_mode, $langcode) { } } +function aes_password_view($uid) { + $output = '
'; + drupal_add_library('system', 'drupal.ajax'); + $link = l(t('Show pass'), 'aes_get_password_callback/' .$uid. '/nojs/', array('attributes' => array('class' => array('use-ajax')))); + $output .= "$link
"; + return $output; +} + +function aes_ajax_callback($uid, $type = 'ajax') { + $output = aes_get_password($uid, TRUE); + if ($type == 'ajax') { + + $commands = array(); + // See ajax_example_advanced.inc for more details on the available commands + // and how to use them. + $commands[] = ajax_command_replace('#aes_password', $output); + $page = array('#type' => 'ajax', '#commands' => $commands); + ajax_deliver($page); + } + else { + $user = user_load($uid, FALSE); + drupal_set_title($user->name . '\'s password'); + return $output; + } +} + /** * Implements hook_user_login(). */