Skip to content

Commit 31e1479

Browse files
committed
[FEATURE] Added PSR-14 Event ModifyUpdatePasswordResponseEvent
Closes #96 (cherry picked from commit 39b5b47)
1 parent 7adcc8b commit 31e1479

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

Classes/Controller/PasswordController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Derhansen\FeChangePwd\Domain\Model\Dto\ChangePassword;
1515
use Derhansen\FeChangePwd\Event\AfterPasswordUpdatedEvent;
16+
use Derhansen\FeChangePwd\Event\ModifyUpdatePasswordResponseEvent;
1617
use Derhansen\FeChangePwd\Exception\InvalidEmailAddressException;
1718
use Derhansen\FeChangePwd\Exception\MissingFeatureToggleException;
1819
use Derhansen\FeChangePwd\Service\FrontendUserService;
@@ -88,10 +89,16 @@ public function updateAction(ChangePassword $changePassword): ResponseInterface
8889
LocalizationUtility::translate('passwordUpdated', 'FeChangePwd'),
8990
LocalizationUtility::translate('passwordUpdated.title', 'FeChangePwd')
9091
);
91-
return $this->redirect('edit');
92+
$response = $this->redirect('edit');
93+
} else {
94+
$response = $this->htmlResponse();
9295
}
9396

94-
return $this->htmlResponse();
97+
$modifyUpdatePasswordResponseEvent = $this->eventDispatcher->dispatch(
98+
new ModifyUpdatePasswordResponseEvent($this->request, $this->settings, $response)
99+
);
100+
101+
return $modifyUpdatePasswordResponseEvent->getResponse();
95102
}
96103

97104
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Derhansen\FeChangePwd\Event;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use Psr\Http\Message\ServerRequestInterface;
9+
10+
/**
11+
* This event is triggered before the response for the updateAction is returned. Listeners can use this event
12+
* to modify the response object (e.g. replace it with a custom response)
13+
*/
14+
final class ModifyUpdatePasswordResponseEvent
15+
{
16+
public function __construct(
17+
private readonly ServerRequestInterface $request,
18+
private readonly array $settings,
19+
private ResponseInterface $response
20+
) {}
21+
22+
public function getRequest(): ServerRequestInterface
23+
{
24+
return $this->request;
25+
}
26+
27+
public function getSettings(): array
28+
{
29+
return $this->settings;
30+
}
31+
32+
public function getResponse(): ResponseInterface
33+
{
34+
return $this->response;
35+
}
36+
37+
public function setResponse(ResponseInterface $response): void
38+
{
39+
$this->response = $response;
40+
}
41+
}

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'author' => 'Torben Hansen',
99
'author_email' => 'torben@derhansen.com',
1010
'state' => 'stable',
11-
'version' => '4.2.2',
11+
'version' => '4.3.0',
1212
'constraints' => [
1313
'depends' => [
1414
'typo3' => '12.4.0-12.4.99'

0 commit comments

Comments
 (0)