File tree Expand file tree Collapse file tree
src/Authentication/TwoFactorAuth Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ declare (strict_types=1 );
9+
10+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider ;
11+
12+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \Factory \EmailFactoryInterface ;
13+
14+ class EmailAdapter
15+ {
16+ public function __construct (
17+ readonly private EmailFactoryInterface $ emailFactory ,
18+ ) {
19+ }
20+
21+ public function getName ()
22+ {
23+ return 'email ' ;
24+ }
25+
26+ public function notify ($ recipient , $ code ): void
27+ {
28+ $ emailModel = $ this ->emailFactory ->create ();
29+ $ emailModel ->sendEmail (
30+ $ recipient ,
31+ 'Your verification code ' ,
32+ "Your verification code is: {$ code }"
33+ );
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ declare (strict_types=1 );
9+
10+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \Factory ;
11+
12+ use OxidEsales \Eshop \Core \Email ;
13+
14+ class EmailFactory implements EmailFactoryInterface
15+ {
16+ public function create (): Email
17+ {
18+ return oxNew (Email::class);
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \Factory ;
9+
10+ use OxidEsales \Eshop \Core \Email ;
11+
12+ interface EmailFactoryInterface
13+ {
14+ public function create (): Email ;
15+ }
Original file line number Diff line number Diff line change 1+ services :
2+ _defaults :
3+ autowire : true
4+ public : false
5+
6+ OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Provider\Factory\EmailFactoryInterface :
7+ class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Provider\Factory\EmailFactory
Original file line number Diff line number Diff line change 1+ imports :
2+ - { resource: Factory/services.yaml }
3+
4+ services :
5+ _defaults :
6+ autowire : true
7+ public : false
8+
9+ OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Provider\EmailAdapter :
10+ tags : [ 'security.twofa.tag.notify.provider' ]
Original file line number Diff line number Diff line change 11imports :
22 - { resource: Factory/services.yaml }
3+ - { resource: Provider/services.yaml }
34 - { resource: Repository/services.yaml }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ declare (strict_types=1 );
9+
10+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Service ;
11+
12+ use Exception ;
13+
14+ class NotifierService implements NotifierServiceInterface
15+ {
16+ private array $ collectedNotifiers ;
17+
18+ public function __construct (
19+ private readonly iterable $ notifiers ,
20+ ) {
21+ $ this ->collectedNotifiers = iterator_to_array ($ this ->notifiers );
22+ }
23+
24+ public function notify (
25+ string $ type ,
26+ string $ recipient ,
27+ string $ code
28+ ): void {
29+ $ notifierFound = array_filter (
30+ $ this ->collectedNotifiers ,
31+ fn ($ notifier ) => $ notifier ->getName () === $ type
32+ );
33+
34+ if (!$ notifierFound ) {
35+ throw new Exception ();
36+ }
37+
38+ $ notifier = reset ($ this ->collectedNotifiers );
39+ $ notifier ->notify ($ recipient , $ code );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Service ;
9+
10+ interface NotifierServiceInterface
11+ {
12+
13+ }
Original file line number Diff line number Diff line change @@ -8,8 +8,12 @@ services:
88
99 OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsServiceInterface :
1010 class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsService
11- public : true
1211
1312 OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeServiceInterface :
1413 class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeService
14+
15+ OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\NotifierServiceInterface :
16+ class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\NotifierService
1517 public : true
18+ arguments :
19+ $notifiers : !tagged 'security.twofa.tag.notify.provider'
You can’t perform that action at this time.
0 commit comments