From 9b4274e8c786ce8643b69447ba0b4d74ce84223f Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 22 Mar 2010 18:55:45 +0000 Subject: - Patch #742366 by moshe weitzman: better UX for OpenID users. --- modules/openid/openid.js | 17 ++++++++++++----- modules/openid/openid.module | 29 +++++++++++++++++++++++++++-- modules/user/user.module | 10 ++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/openid/openid.js b/modules/openid/openid.js index 2f4dfe90d..4c715c1a5 100644 --- a/modules/openid/openid.js +++ b/modules/openid/openid.js @@ -5,14 +5,21 @@ Drupal.behaviors.openid = { attach: function (context) { var loginElements = $('.form-item-name, .form-item-pass, li.openid-link'); var openidElements = $('.form-item-openid-identifier, li.user-link'); + var cookie = $.cookie('Drupal.visitor.openid_identifier'); // This behavior attaches by ID, so is only valid once on a page. - if (!$('#edit-openid-identifier.openid-processed').size() && $('#edit-openid-identifier').val()) { - $('#edit-openid-identifier').addClass('openid-processed'); - loginElements.hide(); - // Use .css('display', 'block') instead of .show() to be Konqueror friendly. - openidElements.css('display', 'block'); + if (!$('#edit-openid-identifier.openid-processed').size()) { + if (cookie) { + $('#edit-openid-identifier').val(cookie); + } + if ($('#edit-openid-identifier').val()) { + $('#edit-openid-identifier').addClass('openid-processed'); + loginElements.hide(); + // Use .css('display', 'block') instead of .show() to Konqueror friendly. + openidElements.css('display', 'block'); + } } + $('li.openid-link:not(.openid-processed)', context) .addClass('openid-processed') .click(function () { diff --git a/modules/openid/openid.module b/modules/openid/openid.module index 6d8cbfbdf..f19810dfa 100644 --- a/modules/openid/openid.module +++ b/modules/openid/openid.module @@ -75,6 +75,30 @@ function openid_user_insert(&$edit, $account, $category) { } } +/** + * Implements hook_user_login(). + * + * Save openid_identifier to visitor cookie. + */ +function openid_user_login(&$edit, $account) { + if (isset($_SESSION['openid'])) { + // The user has logged in via OpenID. + user_cookie_save($_SESSION['openid']['user_login_values'], array('openid_identifier')); + unset($_SESSION['openid']); + } +} + +/** + * Implements hook_user_logout(). + * + * Delete any openid_identifier in visitor cookie. + */ +function openid_user_logout($account) { + if (isset($_COOKIE['Drupal_visitor_openid_identifier'])) { + user_cookie_delete('openid_identifier'); + } +} + /** * Implements hook_form_FORM_ID_alter(). */ @@ -90,8 +114,9 @@ function openid_form_user_login_alter(&$form, &$form_state) { } function _openid_user_login_form_alter(&$form, &$form_state) { - drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css'); - drupal_add_js(drupal_get_path('module', 'openid') . '/openid.js'); + $form['#attached']['css'][] = drupal_get_path('module', 'openid') . '/openid.css'; + $form['#attached']['js'][] = drupal_get_path('module', 'openid') . '/openid.js'; + $form['#attached']['library'][] = array('system', 'cookie'); if (!empty($form_state['input']['openid_identifier'])) { $form['name']['#required'] = FALSE; $form['pass']['#required'] = FALSE; diff --git a/modules/user/user.module b/modules/user/user.module index ac92802cf..59241c3f2 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -3463,6 +3463,16 @@ function user_cookie_save(array $values, array $fields = array('name', 'mail', ' } } +/** + * Delete a visitor information cookie. + * + * @param $cookie_name + * A cookie name such as 'homepage'. + */ +function user_cookie_delete($cookie_name) { + setrawcookie('Drupal.visitor.' . $cookie_name, '', REQUEST_TIME - 3600, '/'); +} + /** * Implements hook_rdf_mapping(). */ -- cgit v1.2.3