diff --git a/core/modules/openid/openid-rtl.css b/core/modules/openid/openid-rtl.css index 861f6d7..8d52c53 100644 --- a/core/modules/openid/openid-rtl.css +++ b/core/modules/openid/openid-rtl.css @@ -1,18 +1,9 @@ -#edit-openid-identifier { +.openid-link, +form.openid-enabled #edit-name { background-position: right 50%; + margin-left: 0; + margin-right: 0.2em; padding-left: 0; padding-right: 20px; } -#user-login .openid-links { - padding-right: 0; -} -html.js #user-login-form li.openid-link, -html.js #user-login li.openid-link { - margin-right: 0; -} -#user-login-form li.openid-link a, -#user-login li.openid-link a { - background-position: right top; - padding: 0 1.5em 0 0; -} diff --git a/core/modules/openid/openid.css b/core/modules/openid/openid.css index 48b170f..ccc18ef 100644 --- a/core/modules/openid/openid.css +++ b/core/modules/openid/openid.css @@ -1,46 +1,9 @@ -#edit-openid-identifier { - background-image: url("login-bg.png"); +.openid-link, +form.openid-enabled #edit-name { + background-image: url('login-bg.png'); background-position: left 50%; /* LTR */ background-repeat: no-repeat; + margin-left: 0.2em; /* LTR */ padding-left: 20px; /* LTR */ } -div.form-item-openid-identifier { - display: block; -} -html.js #user-login-form div.form-item-openid-identifier, -html.js #user-login div.form-item-openid-identifier { - display: none; -} -#user-login-form ul { - margin-top: 0; -} -#user-login ul { - margin: 0 0 5px; -} -#user-login ul li { - margin: 0; -} -#user-login-form .openid-links { - padding-bottom: 0; -} -#user-login .openid-links { - padding-left: 0; /* LTR */ -} -#user-login-form .openid-links li, -#user-login .openid-links li { - display: none; - list-style: none; -} -html.js #user-login-form li.openid-link, -html.js #user-login li.openid-link { - display: block; - margin-left: 0; /* LTR */ -} -#user-login-form li.openid-link a, -#user-login li.openid-link a { - background-image: url("login-bg.png"); - background-position: left top; /* LTR */ - background-repeat: no-repeat; - padding: 0 0 0 1.5em; /* LTR */ -} diff --git a/core/modules/openid/openid.js b/core/modules/openid/openid.js index fdc97fa..19448eb 100644 --- a/core/modules/openid/openid.js +++ b/core/modules/openid/openid.js @@ -2,47 +2,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'); + var self = this; + $('#edit-use-openid', context).once('openid', function() { + // Add the click handler. + var $checkbox = $(this).click(self.setOpenID); + // Initialize the form. + $checkbox.triggerHandler('click'); + }); + }, - // This behavior attaches by ID, so is only valid once on a page. - if (!$('#edit-openid-identifier.openid-processed').size()) { - if (cookie) { - $('#edit-openid-identifier').val(cookie); - } - if ($('#edit-openid-identifier').val() || location.hash == '#openid-login') { - $('#edit-openid-identifier').addClass('openid-processed'); - loginElements.hide(); - // Use .css('display', 'block') instead of .show() to be Konqueror friendly. - openidElements.css('display', 'block'); - } - } - - $('li.openid-link:not(.openid-processed)', context) - .addClass('openid-processed') - .click(function () { - loginElements.hide(); - openidElements.css('display', 'block'); - // Remove possible error message. - $('#edit-name, #edit-pass').removeClass('error'); - $('div.messages.error').hide(); - // Set focus on OpenID Identifier field. - $('#edit-openid-identifier')[0].focus(); - return false; - }); - $('li.user-link:not(.openid-processed)', context) - .addClass('openid-processed') - .click(function () { - openidElements.hide(); - loginElements.css('display', 'block'); - // Clear OpenID Identifier field and remove possible error message. - $('#edit-openid-identifier').val('').removeClass('error'); - $('div.messages.error').css('display', 'block'); - // Set focus on username field. - $('#edit-name')[0].focus(); - return false; - }); + /** + * OpenID-enable/disable the form based on the checkboxes' status. + */ + setOpenID: function () { + $('#user-login, #user-login-form')[this.checked ? 'addClass' : 'removeClass']('openid-enabled'); + $('#edit-pass-wrapper')[this.checked ? 'slideUp' : 'slideDown']('fast'); } }; diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index 7214666..3d2125c 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -137,41 +137,40 @@ function _openid_user_login_form_alter(&$form, &$form_state) { $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', 'jquery.cookie'); - if (!empty($form_state['input']['openid_identifier'])) { - $form['name']['#required'] = FALSE; + + // Change the validate handler when the user wants to log in using OpenID. + if (!empty($form_state['input']['use_openid'])) { $form['pass']['#required'] = FALSE; unset($form['#submit']); $form['#validate'] = array('openid_login_validate'); } - $items = array(); - $items[] = array( - 'data' => l(t('Log in using OpenID'), '#openid-login', array('external' => TRUE)), - 'class' => array('openid-link'), - ); - $items[] = array( - 'data' => l(t('Cancel OpenID login'), '#', array('external' => TRUE)), - 'class' => array('user-link'), + $openid_link = l(t('OpenID'), 'http://openid.net', array( + 'attributes' => array( + 'class' => 'openid-link', + 'title' => t('What is OpenID?'), + 'tabindex' => 5, + ), + )); + $form['use_openid'] = array( + '#type' => 'checkbox', + '#title' => t('Login using !openid-link', array('!openid-link' => $openid_link)), + '#weight' => 5, + '#attributes' => array('tabindex' => 3), ); - $form['openid_links'] = array( - '#theme' => 'item_list', - '#items' => $items, - '#attributes' => array('class' => array('openid-links')), - '#weight' => 1, - ); - - $form['links']['#weight'] = 2; - - $form['openid_identifier'] = array( - '#type' => 'textfield', - '#title' => t('Log in using OpenID'), - '#size' => $form['name']['#size'], - '#maxlength' => 255, - '#weight' => -1, - '#description' => l(t('What is OpenID?'), 'http://openid.net/', array('external' => TRUE)), + // Ensure a sane tab sequence. + $form['name']['#attributes']['tabindex'] = 1; + $form['pass']['#attributes']['tabindex'] = 2; + $form['submit']['#attributes']['tabindex'] = 4; + + $form['openid.return_to'] = array( + '#type' => 'hidden', + '#value' => url('openid/authenticate', array( + 'absolute' => TRUE, + 'query' => user_login_destination(), + )), ); - $form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', array('absolute' => TRUE, 'query' => user_login_destination()))); } /** @@ -240,7 +239,16 @@ function openid_login_validate($form, &$form_state) { $return_to = url('', array('absolute' => TRUE)); } - openid_begin($form_state['values']['openid_identifier'], $return_to, $form_state['values']); + // Kick off OpenID login. + if (openid_begin($form_state['values']['name'], $return_to, $form_state['values']) === FALSE) { + // OpenID login failed. Choose an error message depending on the status. + if (!empty($form_state['values']['pass'])) { + form_set_error('name', t('You entered a password but chose to log in using OpenID. However, the OpenID was not valid. Please ensure you have spelled your ID correctly and that you really want to log in using OpenID.')); + } + else { + form_set_error('name', t('Sorry, that is not a valid OpenID. Please ensure you have spelled your ID correctly.')); + } + } } /** @@ -266,8 +274,7 @@ function openid_begin($claimed_id, $return_to = '', $form_values = array()) { // Quit if the discovery result was empty or if we can't select any service. if (!$discovery || !$service) { - form_set_error('openid_identifier', t('Sorry, that is not a valid OpenID. Ensure you have spelled your ID correctly.')); - return; + return FALSE; } // Set claimed id from discovery. diff --git a/core/modules/openid/openid.pages.inc b/core/modules/openid/openid.pages.inc index dcdb3e9..8ab7154 100644 --- a/core/modules/openid/openid.pages.inc +++ b/core/modules/openid/openid.pages.inc @@ -89,7 +89,10 @@ function openid_user_add_validate($form, &$form_state) { function openid_user_add_submit($form, &$form_state) { $return_to = url('user/' . arg(1) . '/openid', array('absolute' => TRUE)); - openid_begin($form_state['values']['openid_identifier'], $return_to); + // @todo Obviously too late in a submit handler. + if (openid_begin($form_state['values']['openid_identifier'], $return_to) === FALSE) { + form_set_error('openid_identifier', t('Sorry, that is not a valid OpenID. Please ensure you have spelled your ID correctly.')); + } } /** diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 009a716..f0fbd82 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1215,17 +1215,22 @@ function user_login_block($form) { '#maxlength' => USERNAME_MAX_LENGTH, '#size' => 15, '#required' => TRUE, + '#weight' => -10, ); $form['pass'] = array('#type' => 'password', '#title' => t('Password'), '#maxlength' => 60, '#size' => 15, '#required' => TRUE, + '#weight' => 0, ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'), ); + + // Add links to the login block allowing the user to register and retrieve + // a forgotten password. $items = array(); if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) { $items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.')))); @@ -2032,6 +2037,7 @@ function user_login($form, &$form_state) { '#size' => 60, '#maxlength' => USERNAME_MAX_LENGTH, '#required' => TRUE, + '#weight' => -10, ); $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal'))); @@ -2039,6 +2045,7 @@ function user_login($form, &$form_state) { '#title' => t('Password'), '#description' => t('Enter the password that accompanies your username.'), '#required' => TRUE, + '#weight' => 0, ); $form['#validate'] = user_login_default_validators(); $form['actions'] = array('#type' => 'actions');