Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX re-label forgot password for uniq id #11568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Security/MemberAuthenticator/LostPasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\TextField;
use SilverStripe\Security\Member;

/**
* Class LostPasswordForm handles the requests for lost password form generation
Expand All @@ -23,9 +25,15 @@ class LostPasswordForm extends MemberLoginForm
*/
public function getFormFields()
{
return FieldList::create(
EmailField::create('Email', _t('SilverStripe\\Security\\Member.EMAIL', 'Email'))
);
$uniqueIdentifier = Member::config()->get('unique_identifier_field');
$label = Member::singleton()->fieldLabel($uniqueIdentifier);
if ($uniqueIdentifier === 'Email') {
$emailField = EmailField::create('Email', $label);
} else {
// This field needs to still be called Email, but we can re-label it
$emailField = TextField::create('Email', $label);
}
return FieldList::create($emailField);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Security/MemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public function testUpdateCMSFields()
public function testMap_in_groupsReturnsAll()
{
$members = Member::map_in_groups();
$this->assertEquals(17, $members->count(), 'There are 16 members in the mock plus a fake admin');
$this->assertEquals(18, $members->count(), 'There are 17 members in the mock plus a fake admin');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/php/Security/MemberTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@
delocalemember:
Email: [email protected]
Locale: de_DE
username-member:
Email: [email protected]
Username: username1234
22 changes: 22 additions & 0 deletions tests/php/Security/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,28 @@ public function testChangePasswordForLoggedInUsers()
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));
}

public function testLostPasswordFormWithUniqueFieldIdentifier()
{
// override the unique identifier field
Member::config()->set('unique_identifier_field', 'Username');

/** @var Member $admin */
$member = $this->objFromFixture(Member::class, 'username-member');
$member->FailedLoginCount = 99;
$member->LockedOutUntil = DBDatetime::now()->getValue();
$member->write();

// load lostpassword form
$this->get('Security/lostpassword');
$labelElement = $this->cssParser()->getBySelector('#LostPasswordForm_lostPasswordForm_Email_Holder label');

$this->assertEquals(1, count($labelElement ?? []));
$this->assertStringContainsString(
'<label class="left" for="LostPasswordForm_lostPasswordForm_Email">Username</label>',
(string)$labelElement[0]->asXML()
);
}

public function testChangePasswordFromLostPassword()
{
/** @var Member $admin */
Expand Down
Loading