From 1b0d6d22d336d23c0c3bb29cd0468a03ab3fbb4a Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Mon, 5 Aug 2013 00:37:49 -0400 Subject: Issue #1952196 by greggles, sandhya.m: Usability: if a user has just failed a login, default their username on password reset. --- modules/user/user.module | 2 +- modules/user/user.pages.inc | 1 + modules/user/user.test | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'modules/user') diff --git a/modules/user/user.module b/modules/user/user.module index 1b4f86988..5dcd203f1 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -2195,7 +2195,7 @@ function user_login_final_validate($form, &$form_state) { } } else { - form_set_error('name', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password')))); + form_set_error('name', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name'])))))); watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name'])); } } diff --git a/modules/user/user.pages.inc b/modules/user/user.pages.inc index 29fe6cf4d..4cdbc40fa 100644 --- a/modules/user/user.pages.inc +++ b/modules/user/user.pages.inc @@ -36,6 +36,7 @@ function user_pass() { '#size' => 60, '#maxlength' => max(USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH), '#required' => TRUE, + '#default_value' => isset($_GET['name']) ? $_GET['name'] : '', ); // Allow logged in users to request this also. if ($user->uid > 0) { diff --git a/modules/user/user.test b/modules/user/user.test index 3e533abf8..c60f9c533 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -501,6 +501,24 @@ class UserPasswordResetTestCase extends DrupalWebTestCase { $this->drupalGet("user/reset/$account->uid/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login)); $this->assertText(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'), 'Expired password reset request rejected.'); } + + /** + * Prefill the text box on incorrect login via link to password reset page. + */ + function testUserPasswordTextboxFilled() { + $this->drupalGet('user/login'); + $edit = array( + 'name' => $this->randomName(), + 'pass' => $this->randomName(), + ); + $this->drupalPost('user', $edit, t('Log in')); + $this->assertRaw(t('Sorry, unrecognized username or password. Have you forgotten your password?', + array('@password' => url('user/password', array('query' => array('name' => $edit['name'])))))); + unset($edit['pass']); + $this->drupalGet('user/password', array('query' => array('name' => $edit['name']))); + $this->assertFieldByName('name', $edit['name'], 'User name found.'); + } + } /** -- cgit v1.2.3