|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Timpack\PwnedValidator\Plugin; |
| 4 | + |
| 5 | +use Magento\Customer\Api\AccountManagementInterface; |
| 6 | +use Magento\Customer\Api\Data\CustomerInterface; |
| 7 | +use Magento\Framework\Event\ManagerInterface; |
| 8 | + |
| 9 | +class AccountManagementPlugin |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var ManagerInterface |
| 13 | + */ |
| 14 | + protected $eventManager; |
| 15 | + |
| 16 | + /** |
| 17 | + * AccountManagementPlugin constructor. |
| 18 | + * @param ManagerInterface $eventManager |
| 19 | + */ |
| 20 | + public function __construct( |
| 21 | + ManagerInterface $eventManager |
| 22 | + ) { |
| 23 | + $this->eventManager = $eventManager; |
| 24 | + } |
| 25 | + |
| 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 | + |
| 86 | + /** |
| 87 | + * @param AccountManagementInterface $subject |
| 88 | + * @param CustomerInterface $customer |
| 89 | + * @param null $password |
| 90 | + * @param string $redirectUrl |
| 91 | + */ |
| 92 | + public function beforeCreateAccount( |
| 93 | + AccountManagementInterface $subject, |
| 94 | + CustomerInterface $customer, |
| 95 | + $password = null, |
| 96 | + $redirectUrl = '' |
| 97 | + ) { |
| 98 | + $this->dispatchPasswordCheckEvent($password); |
| 99 | + } |
| 100 | +} |
0 commit comments