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