From cea4ecb0061748da22b8f84a03065c09c9174e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sini=C5=A1a=20=C4=8Coli=C4=87?= Date: Fri, 25 Jan 2019 11:36:10 +0100 Subject: [PATCH 1/2] Refactor code to use plugin instead of preference --- Plugin/AccountManagementPlugin.php | 47 ++++++++++++ Rewrite/Model/AccountManagement.php | 115 ---------------------------- etc/di.xml | 5 +- 3 files changed, 50 insertions(+), 117 deletions(-) create mode 100644 Plugin/AccountManagementPlugin.php delete mode 100644 Rewrite/Model/AccountManagement.php diff --git a/Plugin/AccountManagementPlugin.php b/Plugin/AccountManagementPlugin.php new file mode 100644 index 0000000..ef10744 --- /dev/null +++ b/Plugin/AccountManagementPlugin.php @@ -0,0 +1,47 @@ +eventManager = $eventManager; + } + + /** + * @param AccountManagementInterface $subject + * @param CustomerInterface $customer + * @param null $password + * @param string $redirectUrl + */ + public function beforeCreateAccount( + AccountManagementInterface $subject, + CustomerInterface $customer, + $password = null, + $redirectUrl = '' + ) { + if (!is_null($password)) { + $this->eventManager->dispatch( + 'timpack_pwnedvalidator_check_password_strength', + [ + 'password' => $password, + ] + ); + } + } +} diff --git a/Rewrite/Model/AccountManagement.php b/Rewrite/Model/AccountManagement.php deleted file mode 100644 index 9208817..0000000 --- a/Rewrite/Model/AccountManagement.php +++ /dev/null @@ -1,115 +0,0 @@ -eventManager = $eventManager; - } - - /** - * @param string $password - * @throws \Magento\Framework\Exception\InputException - * @return void - */ - protected function checkPasswordStrength($password) - { - parent::checkPasswordStrength($password); - $this->eventManager->dispatch('timpack_pwnedvalidator_check_password_strength', ['password' => $password]); - } -} diff --git a/etc/di.xml b/etc/di.xml index 17e9517..826aede 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -2,8 +2,9 @@ - + + + Magento\Framework\HTTP\Client\Curl From b0659206acc23fadf44d5fb12da9f6dc5b8d6393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sini=C5=A1a=20=C4=8Coli=C4=87?= Date: Tue, 29 Jan 2019 20:52:38 +0100 Subject: [PATCH 2/2] Add support for changing and resetting customer password --- Plugin/AccountManagementPlugin.php | 69 ++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/Plugin/AccountManagementPlugin.php b/Plugin/AccountManagementPlugin.php index ef10744..3bebd04 100644 --- a/Plugin/AccountManagementPlugin.php +++ b/Plugin/AccountManagementPlugin.php @@ -23,6 +23,66 @@ public function __construct( $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 @@ -35,13 +95,6 @@ public function beforeCreateAccount( $password = null, $redirectUrl = '' ) { - if (!is_null($password)) { - $this->eventManager->dispatch( - 'timpack_pwnedvalidator_check_password_strength', - [ - 'password' => $password, - ] - ); - } + $this->dispatchPasswordCheckEvent($password); } }