Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Frequency.php
Go to the documentation of this file.
1 <?php
8 
14 
19 {
23  private $dateTime;
24 
28  private $collectionFactory;
29 
33  private $securityConfig;
34 
38  private $remoteAddress;
39 
46  public function __construct(
47  ConfigInterface $securityConfig,
48  CollectionFactory $collectionFactory,
49  \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
50  RemoteAddress $remoteAddress
51  ) {
52  $this->securityConfig = $securityConfig;
53  $this->collectionFactory = $collectionFactory;
54  $this->dateTime = $dateTime;
55  $this->remoteAddress = $remoteAddress;
56  }
57 
61  public function check($securityEventType, $accountReference = null, $longIp = null)
62  {
63  $isEnabled = $this->securityConfig->getPasswordResetProtectionType() != ResetMethod::OPTION_NONE;
64  $limitTimeBetweenRequests = $this->securityConfig->getMinTimeBetweenPasswordResetRequests();
65  if ($isEnabled && $limitTimeBetweenRequests) {
66  if (null === $longIp) {
67  $longIp = $this->remoteAddress->getRemoteAddress();
68  }
69  $lastRecordCreationTimestamp = $this->loadLastRecordCreationTimestamp(
70  $securityEventType,
71  $accountReference,
72  $longIp
73  );
74  if ($lastRecordCreationTimestamp && (
75  $limitTimeBetweenRequests >
76  ($this->dateTime->gmtTimestamp() - $lastRecordCreationTimestamp)
77  )) {
79  __(
80  'We received too many requests for password resets. '
81  . 'Please wait and try again later or contact %1.',
82  $this->securityConfig->getCustomerServiceEmail()
83  )
84  );
85  }
86  }
87  }
88 
97  private function loadLastRecordCreationTimestamp($securityEventType, $accountReference, $longIp)
98  {
99  $collection = $this->collectionFactory->create($securityEventType, $accountReference, $longIp);
101  $record = $collection->filterLastItem()->getFirstItem();
102 
103  return (int) strtotime($record->getCreatedAt());
104  }
105 }
check($securityEventType, $accountReference=null, $longIp=null)
Definition: Frequency.php:61
__()
Definition: __.php:13
__construct(ConfigInterface $securityConfig, CollectionFactory $collectionFactory, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, RemoteAddress $remoteAddress)
Definition: Frequency.php:46
$dateTime