1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Security\Model\Plugin;
use Magento\Customer\Model\AccountManagement as AccountManagementOriginal;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Config\ScopeInterface;
use Magento\Framework\Exception\SecurityViolationException;
use Magento\Security\Model\PasswordResetRequestEvent;
use Magento\Security\Model\SecurityManager;
/**
* Magento\Customer\Model\AccountManagement decorator
*/
class AccountManagement
{
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;
/**
* @var SecurityManager
*/
protected $securityManager;
/**
* @var int
*/
protected $passwordRequestEvent;
/**
* @var ScopeInterface
*/
private $scope;
/**
* AccountManagement constructor.
*
* @param \Magento\Framework\App\RequestInterface $request
* @param SecurityManager $securityManager
* @param int $passwordRequestEvent
* @param ScopeInterface $scope
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Security\Model\SecurityManager $securityManager,
$passwordRequestEvent = PasswordResetRequestEvent::CUSTOMER_PASSWORD_RESET_REQUEST,
ScopeInterface $scope = null
) {
$this->request = $request;
$this->securityManager = $securityManager;
$this->passwordRequestEvent = $passwordRequestEvent;
$this->scope = $scope ?: ObjectManager::getInstance()->get(ScopeInterface::class);
}
/**
* @param AccountManagementOriginal $accountManagement
* @param string $email
* @param string $template
* @param int|null $websiteId
* @return array
* @throws SecurityViolationException
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeInitiatePasswordReset(
AccountManagementOriginal $accountManagement,
$email,
$template,
$websiteId = null
) {
if ($this->scope->getCurrentScope() == \Magento\Framework\App\Area::AREA_FRONTEND
|| $this->passwordRequestEvent == PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST) {
$this->securityManager->performSecurityCheck(
$this->passwordRequestEvent,
$email
);
}
return [$email, $template, $websiteId];
}
}