File tree Expand file tree Collapse file tree 4 files changed +35
-52
lines changed
Documentation/ExtensionArchitecture/HowTo/Events Expand file tree Collapse file tree 4 files changed +35
-52
lines changed Original file line number Diff line number Diff line change @@ -30,25 +30,9 @@ the name in the :file:`Configuration/Services.yaml` or it is not found.
3030It is best practice to use a descriptive class name and to put it in the
3131namespace :php: `MyVendor\M yExtension\E ventListener `.
3232
33- .. note ::
34- This example is outdated as the used event :ref: `PasswordChangeEvent `
35- does not provide the method :php: `setAsInvalid() ` anymore. However, it
36- illustrates the basic principle of an event listener.
37-
38- .. todo: Adjust example, see also https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/issues/3155
39-
40- .. literalinclude :: _Joh316PasswordInvalidator.php
33+ .. literalinclude :: _Joh316PasswordInformer.php
4134 :language: php
4235
43- Then register the event in your extension's :file: `Configuration/Services.yaml `:
44-
45- .. literalinclude :: _EventServices.yaml
46- :language: yaml
47-
48- Additionally, the :file: `Configuration/Services.yaml ` file allows to define a different
49- method name for the event listener class and to influence the order in which
50- events are loaded. See :ref: `EventDispatcherRegistration ` for details.
51-
5236Dispatch an event
5337=================
5438
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // EXT:my_extension/Classes/EventListener/Joh316PasswordInformer.php
4+ declare (strict_types=1 );
5+
6+ namespace MyVendor \MyExtension \EventListener ;
7+
8+ use Psr \Log \LoggerInterface ;
9+ use TYPO3 \CMS \Core \Attribute \AsEventListener ;
10+ use TYPO3 \CMS \FrontendLogin \Event \PasswordChangeEvent ;
11+
12+ /**
13+ * The password 'joh316' was historically used as the default password for
14+ * the TYPO3 install tool.
15+ * Today this password is an unsecure choice as it is well-known, too short
16+ * and does not contain capital letters or special characters.
17+ */
18+ #[AsEventListener]
19+ final class Joh316PasswordInvalidator
20+ {
21+ public function __construct (
22+ private readonly LoggerInterface $ logger ,
23+ ) {}
24+
25+ public function __invoke (PasswordChangeEvent $ event ): void
26+ {
27+ if ($ event ->getRawPassword () === 'joh316 ' ) {
28+ $ this ->logger ->warning (sprintf (
29+ 'User %s uses the default password "joh316". ' ,
30+ $ event ->getUser ()['username ' ],
31+ ));
32+ }
33+ }
34+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments