Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Quantity.php
Go to the documentation of this file.
1 <?php
8 
14 
19 {
23  protected $collectionFactory;
24 
28  protected $securityConfig;
29 
33  private $remoteAddress;
34 
40  public function __construct(
43  RemoteAddress $remoteAddress
44  ) {
45  $this->securityConfig = $securityConfig;
46  $this->collectionFactory = $collectionFactory;
47  $this->remoteAddress = $remoteAddress;
48  }
49 
53  public function check($securityEventType, $accountReference = null, $longIp = null)
54  {
55  $isEnabled = $this->securityConfig->getPasswordResetProtectionType() != ResetMethod::OPTION_NONE;
56  $allowedAttemptsNumber = $this->securityConfig->getMaxNumberPasswordResetRequests();
57  if ($isEnabled and $allowedAttemptsNumber) {
58  $collection = $this->prepareCollection($securityEventType, $accountReference, $longIp);
59  if ($collection->count() >= $allowedAttemptsNumber) {
61  __(
62  'We received too many requests for password resets. '
63  . 'Please wait and try again later or contact %1.',
64  $this->securityConfig->getCustomerServiceEmail()
65  )
66  );
67  }
68  }
69  }
70 
79  protected function prepareCollection($securityEventType, $accountReference, $longIp)
80  {
81  if (null === $longIp) {
82  $longIp = $this->remoteAddress->getRemoteAddress();
83  }
84  $collection = $this->collectionFactory->create($securityEventType, $accountReference, $longIp);
85  $periodToCheck = $this->securityConfig->getLimitationTimePeriod();
86  $collection->filterByLifetime($periodToCheck);
87 
88  return $collection;
89  }
90 }
__construct(ConfigInterface $securityConfig, CollectionFactory $collectionFactory, RemoteAddress $remoteAddress)
Definition: Quantity.php:40
check($securityEventType, $accountReference=null, $longIp=null)
Definition: Quantity.php:53
__()
Definition: __.php:13
prepareCollection($securityEventType, $accountReference, $longIp)
Definition: Quantity.php:79