Skip to content

Commit b065920

Browse files
committed
Add support for changing and resetting customer password
1 parent cea4ecb commit b065920

File tree

1 file changed

+61
-8
lines changed

1 file changed

+61
-8
lines changed

Plugin/AccountManagementPlugin.php

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,66 @@ public function __construct(
2323
$this->eventManager = $eventManager;
2424
}
2525

26+
/**
27+
* @param string|null $password
28+
*/
29+
private function dispatchPasswordCheckEvent($password)
30+
{
31+
if (!is_null($password)) {
32+
$this->eventManager->dispatch(
33+
'timpack_pwnedvalidator_check_password_strength',
34+
[
35+
'password' => $password,
36+
]
37+
);
38+
}
39+
}
40+
41+
/**
42+
* @param AccountManagementInterface $subject
43+
* @param string $email
44+
* @param string $resetToken
45+
* @param string $newPassword
46+
*/
47+
public function beforeResetPassword(
48+
AccountManagementInterface $subject,
49+
$email,
50+
$resetToken,
51+
$newPassword
52+
) {
53+
$this->dispatchPasswordCheckEvent($newPassword);
54+
}
55+
56+
/**
57+
* @param AccountManagementInterface $subject
58+
* @param string $email
59+
* @param string $currentPassword
60+
* @param string $newPassword
61+
*/
62+
public function beforeChangePassword(
63+
AccountManagementInterface $subject,
64+
$email,
65+
$currentPassword,
66+
$newPassword
67+
) {
68+
$this->dispatchPasswordCheckEvent($newPassword);
69+
}
70+
71+
/**
72+
* @param AccountManagementInterface $subject
73+
* @param string $customerId
74+
* @param string $currentPassword
75+
* @param string $newPassword
76+
*/
77+
public function beforeChangePasswordById(
78+
AccountManagementInterface $subject,
79+
$customerId,
80+
$currentPassword,
81+
$newPassword
82+
) {
83+
$this->dispatchPasswordCheckEvent($newPassword);
84+
}
85+
2686
/**
2787
* @param AccountManagementInterface $subject
2888
* @param CustomerInterface $customer
@@ -35,13 +95,6 @@ public function beforeCreateAccount(
3595
$password = null,
3696
$redirectUrl = ''
3797
) {
38-
if (!is_null($password)) {
39-
$this->eventManager->dispatch(
40-
'timpack_pwnedvalidator_check_password_strength',
41-
[
42-
'password' => $password,
43-
]
44-
);
45-
}
98+
$this->dispatchPasswordCheckEvent($password);
4699
}
47100
}

0 commit comments

Comments
 (0)