Fixes #5550 -- Fix variable used in recent request threshold check.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-06-30 14:51:28 -05:00
parent 0fb17094ed
commit 3716eef54a
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
1 changed files with 5 additions and 5 deletions

View File

@ -90,7 +90,7 @@ final class StationRequestRepository extends AbstractStationBasedRepository
if (!$isAuthenticated) {
// Check for any request (on any station) within the last $threshold_seconds.
$thresholdMins = $station->getRequestThreshold() ?? 5;
$thresholdMins = $station->getRequestDelay() ?? 5;
$thresholdSeconds = $thresholdMins * 60;
// Always have a minimum threshold to avoid flooding.
@ -98,17 +98,17 @@ final class StationRequestRepository extends AbstractStationBasedRepository
$thresholdSeconds = 15;
}
$recent_requests = $this->em->createQuery(
$recentRequests = (int)$this->em->createQuery(
<<<'DQL'
SELECT sr FROM App\Entity\StationRequest sr
SELECT COUNT(sr.id) FROM App\Entity\StationRequest sr
WHERE sr.ip = :user_ip
AND sr.timestamp >= :threshold
DQL
)->setParameter('user_ip', $ip)
->setParameter('threshold', time() - $thresholdSeconds)
->getArrayResult();
->getSingleScalarResult();
if (count($recent_requests) > 0) {
if ($recentRequests > 0) {
throw new Exception(
__('You have submitted a request too recently! Please wait before submitting another one.')
);