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); } }