Index: js/lastuser.js =================================================================== --- js/lastuser.js (revision 0) +++ js/lastuser.js (revision 0) @@ -0,0 +1,29 @@ +/* + * Reads the user cookie and populates the login block with the + * first name of the last logged in user. If a username is found, + * add the question 'Not you?' to prompt for a login. + * + * Note that the user first name in the cookie is its second element + */ + +Drupal.behaviors.myModuleBehavior = function(context){ + var userdetails = readCookie("known_user_role_details"); + if (userdetails != null) { + // Note that "%7C" corresponds to "|" + var firstname = userdetails.split("%7C")[1]; + $("strong.welcome").append(firstname); + $("strong.notyou").append("Not you?"); + } +} + +// Given the name of a cookie, return the associated value +function readCookie(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); + } + return null; +} \ No newline at end of file Index: known_user_role.module =================================================================== --- known_user_role.module (revision 875) +++ known_user_role.module (working copy) @@ -45,7 +45,7 @@ */ function known_user_role_boot() { global $user; - if (!$user->uid && (isset($_COOKIE['known_user_role_uid']) && $_COOKIE['known_user_role_uid'])) { + if (!$user->uid && (isset($_COOKIE['known_user_role_details']) && $_COOKIE['known_user_role_details'])) { // load the known user role $known_user_role = variable_get('known_user_role', array('1' => 'anonymous user')); // if the user is known, set the role @@ -56,10 +56,10 @@ } /** - * Clears the cookie. + * Clear the cookies. */ function known_user_role_clear() { - setcookie('known_user_role_uid', '', time()-1000000, '/'); + setcookie('known_user_role_details', '', time()-1000000, '/'); cache_clear_all(); drupal_goto('user'); } @@ -77,8 +77,8 @@ // load profile data $known_user = user_load($user->uid); } - elseif (isset($_COOKIE['known_user_role_uid']) && $_COOKIE['known_user_role_uid']) { - $known_user = user_load($_COOKIE['known_user_role_uid']); + elseif (isset($_COOKIE['known_user_role_details']) && $_COOKIE['known_user_role_details']) { + $known_user = user_load(explode('|',$_COOKIE['known_user_role_details'],1)); } else { $known_user->name = t('Guest'); @@ -91,6 +91,7 @@ */ function known_user_role_block($op = 'list', $delta = 0, $edit = array()) { global $user; + if ($op == 'list') { $blocks[0]['info'] = t('Known user login'); $blocks[0]['cache'] = BLOCK_NO_CACHE; @@ -100,8 +101,10 @@ $block = array(); switch ($delta) { case 0: + $base = drupal_get_path('module', 'known_user_role'); + drupal_add_js($base . '/js/lastuser.js'); //if the cookie is there or we're logged in, we need to show the welcome message - if ($user->uid || (isset($_COOKIE['known_user_role_uid']) && $_COOKIE['known_user_role_uid'])) { + if ($user->uid || (isset($_COOKIE['known_user_role_details']) && $_COOKIE['known_user_role_details'])) { $block['subject'] = 'Welcome'; //see theme_known_user_welcome() //developer can override the welcome message to known users @@ -137,7 +140,7 @@ */ function theme_known_user_welcome($known_user) { global $user; - + $output = '