Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Plugin/AccountManagementPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace Timpack\PwnedValidator\Plugin;

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Event\ManagerInterface;

class AccountManagementPlugin
{
/**
* @var ManagerInterface
*/
protected $eventManager;

/**
* AccountManagementPlugin constructor.
* @param ManagerInterface $eventManager
*/
public function __construct(
ManagerInterface $eventManager
) {
$this->eventManager = $eventManager;
}

/**
* @param string|null $password
*/
private function dispatchPasswordCheckEvent($password)
{
if (!is_null($password)) {
$this->eventManager->dispatch(
'timpack_pwnedvalidator_check_password_strength',
[
'password' => $password,
]
);
}
}

/**
* @param AccountManagementInterface $subject
* @param string $email
* @param string $resetToken
* @param string $newPassword
*/
public function beforeResetPassword(
AccountManagementInterface $subject,
$email,
$resetToken,
$newPassword
) {
$this->dispatchPasswordCheckEvent($newPassword);
}

/**
* @param AccountManagementInterface $subject
* @param string $email
* @param string $currentPassword
* @param string $newPassword
*/
public function beforeChangePassword(
AccountManagementInterface $subject,
$email,
$currentPassword,
$newPassword
) {
$this->dispatchPasswordCheckEvent($newPassword);
}

/**
* @param AccountManagementInterface $subject
* @param string $customerId
* @param string $currentPassword
* @param string $newPassword
*/
public function beforeChangePasswordById(
AccountManagementInterface $subject,
$customerId,
$currentPassword,
$newPassword
) {
$this->dispatchPasswordCheckEvent($newPassword);
}

/**
* @param AccountManagementInterface $subject
* @param CustomerInterface $customer
* @param null $password
* @param string $redirectUrl
*/
public function beforeCreateAccount(
AccountManagementInterface $subject,
CustomerInterface $customer,
$password = null,
$redirectUrl = ''
) {
$this->dispatchPasswordCheckEvent($password);
}
}
115 changes: 0 additions & 115 deletions Rewrite/Model/AccountManagement.php

This file was deleted.

5 changes: 3 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Timpack\PwnedValidator\Api\ValidatorInterface" type="Timpack\PwnedValidator\Model\Validator"/>
<preference for="Magento\Customer\Model\AccountManagement"
type="Timpack\PwnedValidator\Rewrite\Model\AccountManagement"/>
<type name="Magento\Customer\Api\AccountManagementInterface">
<plugin name="timpack_pwnedvalidator_magento_customer_api_accountmanagementinterface" type="Timpack\PwnedValidator\Plugin\AccountManagementPlugin"/>
</type>
<type name="Timpack\PwnedValidator\Api\ValidatorInterface">
<arguments>
<argument name="httpClient" xsi:type="object">Magento\Framework\HTTP\Client\Curl</argument>
Expand Down