Skip to content

Commit 39b5b47

Browse files
committed
[FEATURE] Added PSR-14 Event ModifyUpdatePasswordResponseEvent
Closes #96
1 parent 2fb1e93 commit 39b5b47

4 files changed

Lines changed: 52 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\Service\FrontendUserService;
1819
use Derhansen\FeChangePwd\Service\SettingsService;
@@ -79,10 +80,16 @@ public function updateAction(ChangePassword $changePassword): ResponseInterface
7980
LocalizationUtility::translate('passwordUpdated', 'FeChangePwd'),
8081
LocalizationUtility::translate('passwordUpdated.title', 'FeChangePwd')
8182
);
82-
return $this->redirect('edit');
83+
$response = $this->redirect('edit');
84+
} else {
85+
$response = $this->htmlResponse();
8386
}
8487

85-
return $this->htmlResponse();
88+
$modifyUpdatePasswordResponseEvent = $this->eventDispatcher->dispatch(
89+
new ModifyUpdatePasswordResponseEvent($this->request, $this->settings, $response)
90+
);
91+
92+
return $modifyUpdatePasswordResponseEvent->getResponse();
8693
}
8794

8895
/**
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+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ The extension currently contains the following PSR-14 events:
145145

146146
* Derhansen\FeChangePwd\Controller\PasswordController
147147
* `AfterPasswordUpdatedEvent`
148+
* `ModifyUpdatePasswordResponseEvent`
148149
* Derhansen\FeChangePwd\Middleware\ForcePasswordChangeRedirect
149150
* `ModifyRedirectUrlParameterEvent`
150151

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' => '5.2.0',
11+
'version' => '5.3.0',
1212
'constraints' => [
1313
'depends' => [
1414
'typo3' => '13.4.0-13.4.99'

0 commit comments

Comments
 (0)