Issue #1772584 by andypost, gumanist, nod_: Get rid of user_login_block() & user_login() in favour of user_login_form().
parent
8dc0f01a04
commit
b38996475d
|
@ -1,18 +1,10 @@
|
||||||
|
|
||||||
#edit-openid-identifier {
|
#edit-openid-identifier {
|
||||||
background-position: right 50%;
|
background-position: right 50%;
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
padding-right: 20px;
|
padding-right: 20px;
|
||||||
}
|
}
|
||||||
#user-login .openid-links {
|
|
||||||
padding-right: 0;
|
#block-user-login .openid-link {
|
||||||
}
|
background-position: right top;
|
||||||
.js #user-login-form li.openid-link,
|
padding: 0 1.5em 0 0;
|
||||||
.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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,15 @@
|
||||||
input[name="openid_identifier"] {
|
#edit-openid-identifier {
|
||||||
background-image: url("login-bg.png");
|
background-image: url("login-bg.png");
|
||||||
background-position: left 50%; /* LTR */
|
background-position: left 50%; /* LTR */
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
padding-left: 20px; /* LTR */
|
padding-left: 20px; /* LTR */
|
||||||
}
|
}
|
||||||
.js form.user-login-block.openid-login-form {
|
|
||||||
|
#block-user-login #openid-login-form {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
form.user-login-block a.openid-link,
|
|
||||||
form.user-login-block a.user-link {
|
#block-user-login .openid-link {
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.js form.user-login-block a.openid-link,
|
|
||||||
.js form.user-login-block a.user-link {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
form.user-login-block a.openid-link {
|
|
||||||
background-image: url("login-bg.png");
|
background-image: url("login-bg.png");
|
||||||
background-position: left top; /* LTR */
|
background-position: left top; /* LTR */
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
|
|
|
@ -4,35 +4,41 @@
|
||||||
|
|
||||||
Drupal.behaviors.openid = {
|
Drupal.behaviors.openid = {
|
||||||
attach: function (context) {
|
attach: function (context) {
|
||||||
var $login = $('#user-login-form');
|
function clearStatus ($form) {
|
||||||
var $openid = $('#openid-login-form');
|
$form.find('input:first').focus();
|
||||||
|
|
||||||
var cookie = $.cookie('Drupal.visitor.openid_identifier');
|
|
||||||
if (cookie || location.hash === '#openid-login') {
|
|
||||||
$openid.show()
|
|
||||||
.find('[name="openid_identifier"]').once('openid')
|
|
||||||
.val(cookie);
|
|
||||||
$login.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Switch between the default login form and the OpenID login form.
|
|
||||||
$('#block-user-login').once('openid').on('click', '.openid-link, .user-link', function (e) {
|
|
||||||
$openid.toggle();
|
|
||||||
$login.toggle();
|
|
||||||
|
|
||||||
var $showForm = $(this).hasClass('openid-link') ? $openid : $login;
|
|
||||||
$showForm.find('input:first').focus();
|
|
||||||
// Clear input fields and reset any validation errors.
|
// Clear input fields and reset any validation errors.
|
||||||
$showForm[0].reset();
|
$form[0].reset();
|
||||||
|
|
||||||
// Reset error state.
|
// Reset error state.
|
||||||
$('#messages').find('div.error').hide();
|
$form.find('.error').removeClass('error');
|
||||||
$('#block-user-login').find('input').removeClass('error');
|
|
||||||
|
|
||||||
// Forget saved identifier.
|
// Forget saved identifier.
|
||||||
$.cookie('Drupal.visitor.openid_identifier', null);
|
$.cookie('Drupal.visitor.openid_identifier', null);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if ($('#block-user-login').length) {
|
||||||
|
var $login_form = $('#user-login-form');
|
||||||
|
var $openid_form = $('#openid-login-form');
|
||||||
|
|
||||||
|
// Change link text and triggers loginchange event.
|
||||||
|
$('#block-user-login .openid-link').toggle(
|
||||||
|
function() {
|
||||||
|
$(this).html(Drupal.t('Cancel OpenID login'));
|
||||||
|
$login_form.hide();
|
||||||
|
$openid_form.show();
|
||||||
|
clearStatus($login_form);
|
||||||
|
// Move focus to OpenID input.
|
||||||
|
$('#edit-openid-identifier').focus();
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
$(this).html(Drupal.t('Log in using OpenID'));
|
||||||
|
$login_form.show();
|
||||||
|
$openid_form.hide();
|
||||||
|
clearStatus($openid_form);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
})(jQuery, Drupal);
|
||||||
})(jQuery);
|
|
||||||
|
|
|
@ -140,30 +140,22 @@ function openid_block_view_user_login_alter(&$block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$block['content']['openid_login_form'] = drupal_get_form('openid_login_form');
|
$block['content']['openid_login_form'] = drupal_get_form('openid_login_form');
|
||||||
$block['content']['openid_login_form']['#attributes']['class'][] = 'user-login-block';
|
|
||||||
$block['content']['openid_login_form']['openid_identifier']['#size'] = $block['content']['user_login_form']['name']['#size'];
|
$block['content']['openid_login_form']['openid_identifier']['#size'] = $block['content']['user_login_form']['name']['#size'];
|
||||||
|
|
||||||
// Add links between the forms.
|
// Put an OpenID link as a first element.
|
||||||
$block['content']['user_login_form']['openid_link'] = array(
|
$block['content']['user_links']['#items'] = array(
|
||||||
'#type' => 'link',
|
l(t('Log in using OpenID'), 'user/login/openid', array(
|
||||||
'#title' => t('Log in using OpenID'),
|
'attributes' => array(
|
||||||
'#href' => '#openid-login',
|
'title' => t('Log in using OpenID.'),
|
||||||
'#options' => array('external' => TRUE),
|
'class' => array('openid-link'),
|
||||||
'#attributes' => array('class' => array('openid-link')),
|
'role' => 'button',
|
||||||
'#attached' => array('css' => array(
|
'tabindex' => 0,
|
||||||
drupal_get_path('module', 'openid') . '/openid.css'),
|
),
|
||||||
),
|
))
|
||||||
'#weight' => 5,
|
) + $block['content']['user_links']['#items'];
|
||||||
);
|
|
||||||
$block['content']['openid_login_form']['user_link'] = array(
|
// Move links under the openid form.
|
||||||
'#type' => 'link',
|
$block['content']['user_links']['#weight'] = 10;
|
||||||
'#title' => t('Cancel OpenID login'),
|
|
||||||
'#href' => '#nogo',
|
|
||||||
'#options' => array('external' => TRUE),
|
|
||||||
'#attributes' => array('class' => array('user-link')),
|
|
||||||
'#weight' => 5,
|
|
||||||
);
|
|
||||||
$block['content']['openid_login_form']['links'] = $block['content']['user_login_form']['links'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -737,7 +729,7 @@ function openid_authentication($response) {
|
||||||
if (!form_get_errors()) {
|
if (!form_get_errors()) {
|
||||||
// Load global $user and perform final login tasks.
|
// Load global $user and perform final login tasks.
|
||||||
$form_state['uid'] = $account->uid;
|
$form_state['uid'] = $account->uid;
|
||||||
user_login_submit(array(), $form_state);
|
user_login_form_submit(array(), $form_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1112,6 +1104,7 @@ function openid_library_info() {
|
||||||
drupal_get_path('module', 'openid') . '/openid.css' => array(),
|
drupal_get_path('module', 'openid') . '/openid.css' => array(),
|
||||||
),
|
),
|
||||||
'dependencies' => array(
|
'dependencies' => array(
|
||||||
|
array('system', 'jquery'),
|
||||||
array('system', 'drupal'),
|
array('system', 'drupal'),
|
||||||
array('system', 'jquery.cookie'),
|
array('system', 'jquery.cookie'),
|
||||||
array('system', 'jquery.once'),
|
array('system', 'jquery.once'),
|
||||||
|
|
|
@ -46,7 +46,7 @@ class SessionHttpsTest extends WebTestBase {
|
||||||
// Test HTTPS session handling by altering the form action to submit the
|
// Test HTTPS session handling by altering the form action to submit the
|
||||||
// login form through https.php, which creates a mock HTTPS request.
|
// login form through https.php, which creates a mock HTTPS request.
|
||||||
$this->drupalGet('user');
|
$this->drupalGet('user');
|
||||||
$form = $this->xpath('//form[@id="user-login"]');
|
$form = $this->xpath('//form[@id="user-login-form"]');
|
||||||
$form[0]['action'] = $this->httpsUrl('user');
|
$form[0]['action'] = $this->httpsUrl('user');
|
||||||
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
|
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
|
||||||
$this->drupalPost(NULL, $edit, t('Log in'));
|
$this->drupalPost(NULL, $edit, t('Log in'));
|
||||||
|
@ -54,7 +54,7 @@ class SessionHttpsTest extends WebTestBase {
|
||||||
// Test a second concurrent session.
|
// Test a second concurrent session.
|
||||||
$this->curlClose();
|
$this->curlClose();
|
||||||
$this->drupalGet('user');
|
$this->drupalGet('user');
|
||||||
$form = $this->xpath('//form[@id="user-login"]');
|
$form = $this->xpath('//form[@id="user-login-form"]');
|
||||||
$form[0]['action'] = $this->httpsUrl('user');
|
$form[0]['action'] = $this->httpsUrl('user');
|
||||||
$this->drupalPost(NULL, $edit, t('Log in'));
|
$this->drupalPost(NULL, $edit, t('Log in'));
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class SessionHttpsTest extends WebTestBase {
|
||||||
// test environments.
|
// test environments.
|
||||||
$this->curlClose();
|
$this->curlClose();
|
||||||
$this->drupalGet('user');
|
$this->drupalGet('user');
|
||||||
$form = $this->xpath('//form[@id="user-login"]');
|
$form = $this->xpath('//form[@id="user-login-form"]');
|
||||||
$form[0]['action'] = $this->httpUrl('user');
|
$form[0]['action'] = $this->httpUrl('user');
|
||||||
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
|
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
|
||||||
$this->drupalPost(NULL, $edit, t('Log in'));
|
$this->drupalPost(NULL, $edit, t('Log in'));
|
||||||
|
@ -136,7 +136,7 @@ class SessionHttpsTest extends WebTestBase {
|
||||||
|
|
||||||
// Check that user login form action is secure.
|
// Check that user login form action is secure.
|
||||||
$this->drupalGet('user');
|
$this->drupalGet('user');
|
||||||
$form = $this->xpath('//form[@id="user-login"]');
|
$form = $this->xpath('//form[@id="user-login-form"]');
|
||||||
$this->assertEqual(substr($form[0]['action'], 0, 6), 'https:', 'Login form action is secure');
|
$this->assertEqual(substr($form[0]['action'], 0, 6), 'https:', 'Login form action is secure');
|
||||||
$form[0]['action'] = $this->httpsUrl('user');
|
$form[0]['action'] = $this->httpsUrl('user');
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ class SessionHttpsTest extends WebTestBase {
|
||||||
|
|
||||||
// Mock a login to the secure site using the secure session cookie.
|
// Mock a login to the secure site using the secure session cookie.
|
||||||
$this->drupalGet('user');
|
$this->drupalGet('user');
|
||||||
$form = $this->xpath('//form[@id="user-login"]');
|
$form = $this->xpath('//form[@id="user-login-form"]');
|
||||||
$form[0]['action'] = $this->httpsUrl('user');
|
$form[0]['action'] = $this->httpsUrl('user');
|
||||||
$this->drupalPost(NULL, $edit, t('Log in'));
|
$this->drupalPost(NULL, $edit, t('Log in'));
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ function session_test_user_login($edit = array(), $user = NULL) {
|
||||||
/**
|
/**
|
||||||
* Implements hook_form_FORM_ID_alter().
|
* Implements hook_form_FORM_ID_alter().
|
||||||
*/
|
*/
|
||||||
function session_test_form_user_login_alter(&$form) {
|
function session_test_form_user_login_form_alter(&$form) {
|
||||||
$form['#https'] = TRUE;
|
$form['#https'] = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ class RegisterFormController extends AccountFormController {
|
||||||
elseif (!$admin && !config('user.settings')->get('verify_mail') && $account->status) {
|
elseif (!$admin && !config('user.settings')->get('verify_mail') && $account->status) {
|
||||||
_user_mail_notify('register_no_approval_required', $account);
|
_user_mail_notify('register_no_approval_required', $account);
|
||||||
$form_state['uid'] = $account->uid;
|
$form_state['uid'] = $account->uid;
|
||||||
user_login_submit(array(), $form_state);
|
user_login_form_submit(array(), $form_state);
|
||||||
drupal_set_message(t('Registration successful. You are now logged in.'));
|
drupal_set_message(t('Registration successful. You are now logged in.'));
|
||||||
$form_state['redirect'] = '';
|
$form_state['redirect'] = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -731,41 +731,6 @@ function user_validate_current_pass(&$form, &$form_state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_login_block($form) {
|
|
||||||
$form['#action'] = url(current_path(), array('query' => drupal_get_destination(), 'external' => FALSE));
|
|
||||||
$form['#id'] = 'user-login-form';
|
|
||||||
$form['#validate'] = user_login_default_validators();
|
|
||||||
$form['#submit'][] = 'user_login_submit';
|
|
||||||
$form['name'] = array('#type' => 'textfield',
|
|
||||||
'#title' => t('Username'),
|
|
||||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
|
||||||
'#size' => 15,
|
|
||||||
'#required' => TRUE,
|
|
||||||
);
|
|
||||||
$form['pass'] = array('#type' => 'password',
|
|
||||||
'#title' => t('Password'),
|
|
||||||
'#maxlength' => 60,
|
|
||||||
'#size' => 15,
|
|
||||||
'#required' => TRUE,
|
|
||||||
);
|
|
||||||
$items = array();
|
|
||||||
if (config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
|
||||||
$items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
|
|
||||||
}
|
|
||||||
$items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
|
|
||||||
$form['links'] = array(
|
|
||||||
'#theme' => 'item_list',
|
|
||||||
'#items' => $items,
|
|
||||||
'#weight' => 10,
|
|
||||||
);
|
|
||||||
$form['actions'] = array('#type' => 'actions');
|
|
||||||
$form['actions']['submit'] = array('#type' => 'submit',
|
|
||||||
'#value' => t('Log in'),
|
|
||||||
'#weight' => 20,
|
|
||||||
);
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_block_info().
|
* Implements hook_block_info().
|
||||||
*/
|
*/
|
||||||
|
@ -841,9 +806,39 @@ function user_block_view($delta = '') {
|
||||||
case 'login':
|
case 'login':
|
||||||
// For usability's sake, avoid showing two login forms on one page.
|
// For usability's sake, avoid showing two login forms on one page.
|
||||||
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
|
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
|
||||||
|
// Customize the login form.
|
||||||
|
$form = drupal_get_form('user_login_form');
|
||||||
|
unset($form['name']['#attributes']['autofocus']);
|
||||||
|
unset($form['name']['#description']);
|
||||||
|
unset($form['pass']['#description']);
|
||||||
|
$form['name']['#size'] = 15;
|
||||||
|
$form['pass']['#size'] = 15;
|
||||||
|
$form['#action'] = url(current_path(), array('query' => drupal_get_destination(), 'external' => FALSE));
|
||||||
|
// Build action links.
|
||||||
|
$items = array();
|
||||||
|
if (config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) {
|
||||||
|
$items['create_account'] = l(t('Create new account'), 'user/register', array(
|
||||||
|
'attributes' => array(
|
||||||
|
'title' => t('Create a new user account.'),
|
||||||
|
'class' => array('create-account-link'),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$items['request_password'] = l(t('Request new password'), 'user/password', array(
|
||||||
|
'attributes' => array(
|
||||||
|
'title' => t('Request new password via e-mail.'),
|
||||||
|
'class' => array('request-password-link'),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
// Build a block as renderable array.
|
||||||
$block['subject'] = t('User login');
|
$block['subject'] = t('User login');
|
||||||
$block['content']['user_login_form'] = drupal_get_form('user_login_block');
|
$block['content'] = array(
|
||||||
|
'user_login_form' => $form,
|
||||||
|
'user_links' => array(
|
||||||
|
'#theme' => 'item_list',
|
||||||
|
'#items' => $items,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return $block;
|
return $block;
|
||||||
|
|
||||||
|
@ -1577,29 +1572,33 @@ function user_set_authmaps($account, $authmaps) {
|
||||||
*
|
*
|
||||||
* @ingroup forms
|
* @ingroup forms
|
||||||
*/
|
*/
|
||||||
function user_login($form, &$form_state) {
|
function user_login_form($form, &$form_state) {
|
||||||
|
|
||||||
// Display login form:
|
// Display login form:
|
||||||
$form['name'] = array('#type' => 'textfield',
|
$form['name'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
'#title' => t('Username'),
|
'#title' => t('Username'),
|
||||||
'#size' => 60,
|
'#size' => 60,
|
||||||
'#maxlength' => USERNAME_MAX_LENGTH,
|
'#maxlength' => USERNAME_MAX_LENGTH,
|
||||||
|
'#description' => t('Enter your @s username.', array('@s' => config('system.site')->get('name'))),
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
'#attributes' => array(
|
'#attributes' => array(
|
||||||
'autofocus' => 'autofocus',
|
'autofocus' => 'autofocus',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$form['name']['#description'] = t('Enter your @s username.', array('@s' => config('system.site')->get('name')));
|
$form['pass'] = array(
|
||||||
$form['pass'] = array('#type' => 'password',
|
'#type' => 'password',
|
||||||
'#title' => t('Password'),
|
'#title' => t('Password'),
|
||||||
|
'#size' => 60,
|
||||||
'#description' => t('Enter the password that accompanies your username.'),
|
'#description' => t('Enter the password that accompanies your username.'),
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
);
|
);
|
||||||
$form['#validate'] = user_login_default_validators();
|
|
||||||
$form['actions'] = array('#type' => 'actions');
|
$form['actions'] = array('#type' => 'actions');
|
||||||
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
|
||||||
|
|
||||||
|
$form['#validate'] = user_login_default_validators();
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1781,7 +1780,7 @@ function user_login_finalize(&$edit = array()) {
|
||||||
* tasks. The user is then redirected to the My Account page. Setting the
|
* tasks. The user is then redirected to the My Account page. Setting the
|
||||||
* destination in the query string overrides the redirect.
|
* destination in the query string overrides the redirect.
|
||||||
*/
|
*/
|
||||||
function user_login_submit($form, &$form_state) {
|
function user_login_form_submit($form, &$form_state) {
|
||||||
global $user;
|
global $user;
|
||||||
$user = user_load($form_state['uid']);
|
$user = user_load($form_state['uid']);
|
||||||
$form_state['redirect'] = 'user/' . $user->uid;
|
$form_state['redirect'] = 'user/' . $user->uid;
|
||||||
|
@ -1816,7 +1815,7 @@ function user_external_login_register($name, $module) {
|
||||||
|
|
||||||
// Log user in.
|
// Log user in.
|
||||||
$form_state['uid'] = $account->uid;
|
$form_state['uid'] = $account->uid;
|
||||||
user_login_submit(array(), $form_state);
|
user_login_form_submit(array(), $form_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -423,6 +423,6 @@ function user_page() {
|
||||||
return new RedirectResponse(url('user/' . $user->uid, array('absolute' => TRUE)));
|
return new RedirectResponse(url('user/' . $user->uid, array('absolute' => TRUE)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return drupal_get_form('user_login');
|
return drupal_get_form('user_login_form');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue