Skip to content

Commit

Permalink
Merge pull request #476 from creative-commoners/pulls/5/upgarde-cms5
Browse files Browse the repository at this point in the history
DEP PHP Support in CMS5
  • Loading branch information
emteknetnz authored Jan 17, 2023
2 parents 8e6a6c8 + 34af8cd commit 71f176d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/framework": "^4.10",
"silverstripe/admin": "^1.1",
"silverstripe/siteconfig": "^4.1",
"defuse/php-encryption": "^2.2",
"silverstripe/login-forms": "^4.0",
"silverstripe/security-extensions": "^4.0"
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/admin": "^2",
"silverstripe/siteconfig": "^5",
"defuse/php-encryption": "^2.3",
"silverstripe/login-forms": "^5",
"silverstripe/security-extensions": "^5"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
"squizlabs/php_codesniffer": "^3"
},
"conflict": {
"silverstripe/subsites": "<2.2.2 || 2.3.0",
Expand Down
9 changes: 7 additions & 2 deletions src/Extension/AccountReset/SecurityAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class SecurityAdminExtension extends Extension
'reset',
];

private static $url_handlers = [
'users/reset/$ID' => 'reset',
];

/**
* @var string[]
*/
Expand Down Expand Up @@ -135,12 +139,13 @@ protected function sendResetEmail($member)
->addData('AccountResetLink', $this->getAccountResetLink($member, $token))
->addData('Member', $member)
->setTo($member->Email);

return $email->send();
$email->send();
} catch (Exception $e) {
$this->logger->info('WARNING: Account Reset Email failed to send: ' . $e->getMessage());
return false;
}

return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/FormField/RegisteredMFAMethodListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getSchemaDataDefaults()
'backupCreationDate' => $this->getBackupMethod()
? $this->getBackupMethod()->Created
: null,
'resetEndpoint' => SecurityAdmin::singleton()->Link("reset/{$this->value}"),
'resetEndpoint' => SecurityAdmin::singleton()->Link("users/reset/{$this->value}"),
'isMFARequired' => EnforcementManager::create()->isMFARequired(),
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testEndpointRequiresCSRF()
/** @var Member $member */
$member = $this->objFromFixture(Member::class, 'squib');

$response = $this->post(SecurityAdmin::singleton()->Link("reset/{$member->ID}"), [true]);
$response = $this->post(SecurityAdmin::singleton()->Link("users/reset/{$member->ID}"), [true]);

$this->assertEquals(400, $response->getStatusCode(), $response->getBody());
$this->assertStringContainsString('Invalid or missing CSRF', $response->getBody());
Expand All @@ -52,7 +52,7 @@ public function testResetCanBeInitiatedByAdmin()
$member = $this->objFromFixture(Member::class, 'squib');

$response = $this->post(
SecurityAdmin::singleton()->Link("reset/{$member->ID}"),
SecurityAdmin::singleton()->Link("users/reset/{$member->ID}"),
[true],
null,
null,
Expand All @@ -71,7 +71,7 @@ public function testResetCannotBeInitiatedByStandardUser()
$member = $this->objFromFixture(Member::class, 'admin');

$response = $this->post(
SecurityAdmin::singleton()->Link("reset/{$member->ID}"),
SecurityAdmin::singleton()->Link("users/reset/{$member->ID}"),
[true],
null,
null,
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Service/RegisteredMethodManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testRegisterForMemberWritesToExistingRegisteredMethod()
public function testRegisterForMemberCreatesNewMethod()
{
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Mike']);
$member = Member::create(['FirstName' => 'Mike', 'Email' => '[email protected]']);
$member->write();
$method = new BackupCodeMethod();

Expand All @@ -72,7 +72,7 @@ public function testRegisterForMemberCreatesNewMethod()
public function testRegisterForMemberAssignsDefaultRegisteredMethod()
{
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Mike']);
$member = Member::create(['FirstName' => 'Mike', 'Email' => '[email protected]']);
$member->write();
$method = new BackupCodeMethod();

Expand Down Expand Up @@ -127,7 +127,7 @@ public function testRegisterBackupMethodDoesNotSendEmail()
public function testRegisterForMemberDoesNothingWithNoData()
{
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Michelle']);
$member = Member::create(['FirstName' => 'Michelle', 'Email' => '[email protected]']);
$member->write();
$method = new BackupCodeMethod();

Expand Down

0 comments on commit 71f176d

Please sign in to comment.