AccountManagement.php 2.5 KB

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