diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-03-22 18:55:45 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-03-22 18:55:45 +0000 |
commit | 9b4274e8c786ce8643b69447ba0b4d74ce84223f (patch) | |
tree | 70b8fcfd0200968f6e4cecf9ff04897d28a8a46f /modules/openid | |
parent | e8d18e41fc25af8dad5746e5b3bd6982c2492c2e (diff) | |
download | brdo-9b4274e8c786ce8643b69447ba0b4d74ce84223f.tar.gz brdo-9b4274e8c786ce8643b69447ba0b4d74ce84223f.tar.bz2 |
- Patch #742366 by moshe weitzman: better UX for OpenID users.
Diffstat (limited to 'modules/openid')
-rw-r--r-- | modules/openid/openid.js | 17 | ||||
-rw-r--r-- | modules/openid/openid.module | 29 |
2 files changed, 39 insertions, 7 deletions
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 @@ -76,6 +76,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(). */ function openid_form_user_login_block_alter(&$form, &$form_state) { @@ -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; |