Skip to content

Commit

Permalink
Merge branch '5.3' into 5
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 29, 2025
2 parents 31e5e4f + 690838b commit f48a01e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
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 @@ -1033,7 +1033,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

0 comments on commit f48a01e

Please sign in to comment.