Skip to content

Commit cea4ecb

Browse files
committed
Refactor code to use plugin instead of preference
1 parent 607f446 commit cea4ecb

File tree

3 files changed

+50
-117
lines changed

3 files changed

+50
-117
lines changed

Plugin/AccountManagementPlugin.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Timpack\PwnedValidator\Plugin;
4+
5+
use Magento\Customer\Api\AccountManagementInterface;
6+
use Magento\Customer\Api\Data\CustomerInterface;
7+
use Magento\Framework\Event\ManagerInterface;
8+
9+
class AccountManagementPlugin
10+
{
11+
/**
12+
* @var ManagerInterface
13+
*/
14+
protected $eventManager;
15+
16+
/**
17+
* AccountManagementPlugin constructor.
18+
* @param ManagerInterface $eventManager
19+
*/
20+
public function __construct(
21+
ManagerInterface $eventManager
22+
) {
23+
$this->eventManager = $eventManager;
24+
}
25+
26+
/**
27+
* @param AccountManagementInterface $subject
28+
* @param CustomerInterface $customer
29+
* @param null $password
30+
* @param string $redirectUrl
31+
*/
32+
public function beforeCreateAccount(
33+
AccountManagementInterface $subject,
34+
CustomerInterface $customer,
35+
$password = null,
36+
$redirectUrl = ''
37+
) {
38+
if (!is_null($password)) {
39+
$this->eventManager->dispatch(
40+
'timpack_pwnedvalidator_check_password_strength',
41+
[
42+
'password' => $password,
43+
]
44+
);
45+
}
46+
}
47+
}

Rewrite/Model/AccountManagement.php

Lines changed: 0 additions & 115 deletions
This file was deleted.

etc/di.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
44
<preference for="Timpack\PwnedValidator\Api\ValidatorInterface" type="Timpack\PwnedValidator\Model\Validator"/>
5-
<preference for="Magento\Customer\Model\AccountManagement"
6-
type="Timpack\PwnedValidator\Rewrite\Model\AccountManagement"/>
5+
<type name="Magento\Customer\Api\AccountManagementInterface">
6+
<plugin name="timpack_pwnedvalidator_magento_customer_api_accountmanagementinterface" type="Timpack\PwnedValidator\Plugin\AccountManagementPlugin"/>
7+
</type>
78
<type name="Timpack\PwnedValidator\Api\ValidatorInterface">
89
<arguments>
910
<argument name="httpClient" xsi:type="object">Magento\Framework\HTTP\Client\Curl</argument>

0 commit comments

Comments
 (0)