<?php
namespace AppBundle\Repository;
use AppBundle\Entity\AccessLog;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* AccessLogRepository.
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class AccessLogRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, AccessLog::class);
}
/**
* get the number of failed logins for an ip.
*
* @param string $ip
*/
public function findFailureQtyByIp($ip)
{
// current date -5 minutes
$date = (new \DateTime('-5 minutes'))->format('Y-m-d H:i:s');
$result = $this->getEntityManager()
->createQuery(
'SELECT l FROM AppBundle:AccessLog l
WHERE l.ip = :ip
AND l.created > :date
AND l.type = \'failure\''
)
->setParameter('ip', $ip)
->setParameter('date', $date)
->getResult();
return count($result);
}
}