/** * Create collection * * @param int $securityEventType * @return \Magento\Security\Model\ResourceModel\PasswordResetRequestEvent\Collection */ protected function createCollection($securityEventType) { /** @var RequestCollection $passwordResetRequestEventCollection */ $passwordResetRequestEventCollection = $this->passwordResetRequestEventCollectionFactory->create(); $passwordResetRequestEventCollection->filterByRequestType($securityEventType); return $passwordResetRequestEventCollection; }
/** * Load last record creation timestamp * * @param int $securityEventType * @param string $accountReference * @param int $longIp * @return int */ private function loadLastRecordCreationTimestamp($securityEventType, $accountReference, $longIp) { $collection = $this->collectionFactory->create($securityEventType, $accountReference, $longIp); /** @var \Magento\Security\Model\PasswordResetRequestEvent $record */ $record = $collection->filterLastItem()->getFirstItem(); return (int) strtotime($record->getCreatedAt()); }
/** * Prepare collection * * @param int $securityEventType * @param string $accountReference * @param int $longIp * @return \Magento\Security\Model\ResourceModel\PasswordResetRequestEvent\Collection */ protected function prepareCollection($securityEventType, $accountReference, $longIp) { if (null === $longIp) { $longIp = $this->remoteAddress->getRemoteAddress(); } $collection = $this->collectionFactory->create($securityEventType, $accountReference, $longIp); $periodToCheck = $this->securityConfig->getLimitationTimePeriod(); $collection->filterByLifetime($periodToCheck); return $collection; }
/** * @param int $limitMethod * @param int $securityEventType * @param string $accountReference * @param string $longIp * @dataProvider createDataProvider */ public function testCreate($limitMethod, $securityEventType = null, $accountReference = null, $longIp = null) { $collectionMcok = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $this->objectManagerMock->expects($this->once())->method('create')->willReturn($collectionMcok); if ($securityEventType !== null) { $this->securityConfigMock->expects($this->once())->method('getPasswordResetProtectionType')->willReturn($limitMethod); } if ($limitMethod == ResetMethod::OPTION_BY_EMAIL) { $collectionMcok->expects($this->once())->method('filterByAccountReference')->with($accountReference); } if ($limitMethod == ResetMethod::OPTION_BY_IP) { $collectionMcok->expects($this->once())->method('filterByIp')->with($longIp); } if ($limitMethod == ResetMethod::OPTION_BY_IP_AND_EMAIL) { $collectionMcok->expects($this->once())->method('filterByIpOrAccountReference')->with($longIp, $accountReference); } $this->model->create($securityEventType, $accountReference, $longIp); }
/** * Clean expired Admin Sessions * * @return $this */ public function cleanExpiredRecords() { $this->passwordResetRequestEventCollectionFactory->create()->deleteRecordsOlderThen($this->securityConfig->getCurrentTimestamp() - self::SECURITY_CONTROL_RECORDS_LIFE_TIME); return $this; }