Commit b3899647 authored by webchick's avatar webchick
Browse files

Issue #1772584 by andypost, gumanist, nod_: Get rid of user_login_block() &...

Issue #1772584 by andypost, gumanist, nod_: Get rid of user_login_block() & user_login() in favour of user_login_form().
parent 8dc0f01a
#edit-openid-identifier {
background-position: right 50%;
padding-left: 0;
padding-right: 20px;
}
#user-login .openid-links {
padding-right: 0;
}
.js #user-login-form li.openid-link,
.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;
#block-user-login .openid-link {
background-position: right top;
padding: 0 1.5em 0 0;
}
input[name="openid_identifier"] {
#edit-openid-identifier {
background-image: url("login-bg.png");
background-position: left 50%; /* LTR */
background-repeat: no-repeat;
padding-left: 20px; /* LTR */
}
.js form.user-login-block.openid-login-form {
#block-user-login #openid-login-form {
display: none;
}
form.user-login-block a.openid-link,
form.user-login-block a.user-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 {
#block-user-login .openid-link {
background-image: url("login-bg.png");
background-position: left top; /* LTR */
background-repeat: no-repeat;
......
......@@ -4,35 +4,41 @@
Drupal.behaviors.openid = {
attach: function (context) {
var $login = $('#user-login-form');
var $openid = $('#openid-login-form');
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();
function clearStatus ($form) {
$form.find('input:first').focus();
// Clear input fields and reset any validation errors.
$showForm[0].reset();
$form[0].reset();
// Reset error state.
$('#messages').find('div.error').hide();
$('#block-user-login').find('input').removeClass('error');
$form.find('.error').removeClass('error');
// Forget saved identifier.
$.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);
})(jQuery, Drupal);
......@@ -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']['#attributes']['class'][] = 'user-login-block';
$block['content']['openid_login_form']['openid_identifier']['#size'] = $block['content']['user_login_form']['name']['#size'];
// Add links between the forms.
$block['content']['user_login_form']['openid_link'] = array(
'#type' => 'link',
'#title' => t('Log in using OpenID'),
'#href' => '#openid-login',
'#options' => array('external' => TRUE),
'#attributes' => array('class' => array('openid-link')),
'#attached' => array('css' => array(
drupal_get_path('module', 'openid') . '/openid.css'),
),
'#weight' => 5,
);
$block['content']['openid_login_form']['user_link'] = array(
'#type' => 'link',
'#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'];
// Put an OpenID link as a first element.
$block['content']['user_links']['#items'] = array(
l(t('Log in using OpenID'), 'user/login/openid', array(
'attributes' => array(
'title' => t('Log in using OpenID.'),
'class' => array('openid-link'),
'role' => 'button',
'tabindex' => 0,
),
))
) + $block['content']['user_links']['#items'];
// Move links under the openid form.
$block['content']['user_links']['#weight'] = 10;
}
/**
......@@ -737,7 +729,7 @@ function openid_authentication($response) {
if (!form_get_errors()) {
// Load global $user and perform final login tasks.
$form_state['uid'] = $account->uid;
user_login_submit(array(), $form_state);
user_login_form_submit(array(), $form_state);
}
}
else {
......@@ -1112,6 +1104,7 @@ function openid_library_info() {
drupal_get_path('module', 'openid') . '/openid.css' => array(),
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'jquery.cookie'),
array('system', 'jquery.once'),
......
......@@ -46,7 +46,7 @@ protected function testHttpsSession() {
// Test HTTPS session handling by altering the form action to submit the
// login form through https.php, which creates a mock HTTPS request.
$this->drupalGet('user');
$form = $this->xpath('//form[@id="user-login"]');
$form = $this->xpath('//form[@id="user-login-form"]');
$form[0]['action'] = $this->httpsUrl('user');
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
$this->drupalPost(NULL, $edit, t('Log in'));
......@@ -54,7 +54,7 @@ protected function testHttpsSession() {
// Test a second concurrent session.
$this->curlClose();
$this->drupalGet('user');
$form = $this->xpath('//form[@id="user-login"]');
$form = $this->xpath('//form[@id="user-login-form"]');
$form[0]['action'] = $this->httpsUrl('user');
$this->drupalPost(NULL, $edit, t('Log in'));
......@@ -89,7 +89,7 @@ protected function testHttpsSession() {
// test environments.
$this->curlClose();
$this->drupalGet('user');
$form = $this->xpath('//form[@id="user-login"]');
$form = $this->xpath('//form[@id="user-login-form"]');
$form[0]['action'] = $this->httpUrl('user');
$edit = array('name' => $user->name, 'pass' => $user->pass_raw);
$this->drupalPost(NULL, $edit, t('Log in'));
......@@ -136,7 +136,7 @@ protected function testHttpsSession() {
// Check that user login form action is secure.
$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');
$form[0]['action'] = $this->httpsUrl('user');
......@@ -193,7 +193,7 @@ protected function testHttpsSession() {
// Mock a login to the secure site using the secure session cookie.
$this->drupalGet('user');
$form = $this->xpath('//form[@id="user-login"]');
$form = $this->xpath('//form[@id="user-login-form"]');
$form[0]['action'] = $this->httpsUrl('user');
$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().
*/
function session_test_form_user_login_alter(&$form) {
function session_test_form_user_login_form_alter(&$form) {
$form['#https'] = TRUE;
}
......
......@@ -124,7 +124,7 @@ public function save(array $form, array &$form_state) {
elseif (!$admin && !config('user.settings')->get('verify_mail') && $account->status) {
_user_mail_notify('register_no_approval_required', $account);
$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.'));
$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().
*/
......@@ -841,9 +806,39 @@ function user_block_view($delta = '') {
case 'login':
// For usability's sake, avoid showing two login forms on one page.
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['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;
......@@ -1577,29 +1572,33 @@ function user_set_authmaps($account, $authmaps) {
*
* @ingroup forms
*/
function user_login($form, &$form_state) {
function user_login_form($form, &$form_state) {
// Display login form:
$form['name'] = array('#type' => 'textfield',
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#size' => 60,
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Enter your @s username.', array('@s' => config('system.site')->get('name'))),
'#required' => TRUE,
'#attributes' => array(
'autofocus' => 'autofocus',
),
);
$form['name']['#description'] = t('Enter your @s username.', array('@s' => config('system.site')->get('name')));
$form['pass'] = array('#type' => 'password',
$form['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#size' => 60,
'#description' => t('Enter the password that accompanies your username.'),
'#required' => TRUE,
);
$form['#validate'] = user_login_default_validators();
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
$form['#validate'] = user_login_default_validators();
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
* 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;
$user = user_load($form_state['uid']);
$form_state['redirect'] = 'user/' . $user->uid;
......@@ -1816,7 +1815,7 @@ function user_external_login_register($name, $module) {
// Log user in.
$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)));
}
else {
return drupal_get_form('user_login');
return drupal_get_form('user_login_form');
}
}
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