Skip to content

Commit

Permalink
Add support for changing and resetting customer password
Browse files Browse the repository at this point in the history
  • Loading branch information
sinisa-colic committed Jan 29, 2019
1 parent cea4ecb commit b065920
Showing 1 changed file with 61 additions and 8 deletions.
69 changes: 61 additions & 8 deletions Plugin/AccountManagementPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

0 comments on commit b065920

Please sign in to comment.