Commit 9b4274e8 authored by Dries's avatar Dries

- Patch #742366 by moshe weitzman: better UX for OpenID users.

parent e8d18e41
......@@ -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()) {
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 be Konqueror friendly.
// 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 () {
......
......@@ -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;
......
......@@ -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().
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment