src/Repository/UserRepository.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\User;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  7. use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @method User|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method User|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method User[]    findAll()
  13.  * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registryUser::class);
  20.     }
  21.     /**
  22.      * Used to upgrade (rehash) the user's password automatically over time.
  23.      */
  24.     public function upgradePassword(UserInterface $userstring $newEncodedPassword): void
  25.     {
  26.         if (!$user instanceof User) {
  27.             throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.'\get_class($user)));
  28.         }
  29.         $user->setPassword($newEncodedPassword);
  30.         $this->_em->persist($user);
  31.         $this->_em->flush();
  32.     }
  33.     public function loadUserByUsername($username)
  34.     {
  35.         return $this->createQueryBuilder('u')
  36.             ->where('u.username = :username OR u.email = :email')
  37.             ->setParameter('username'$username)
  38.             ->setParameter('email'$username)
  39.             ->getQuery()
  40.             ->getOneOrNullResult();
  41.     }
  42.     public function countRecentLoginAttempts($id)
  43.     {
  44.         return $this->createQueryBuilder('u')
  45.                     ->select('u.authentication_failure','u.locked')
  46.                     ->where('u.locked IS NOT NULL')
  47.                     ->andWhere('u.id = :id')
  48.                     ->setParameter('id'$id)
  49.                     ->getQuery()
  50.                     ->getOneOrNullResult()
  51.         ;
  52.     }
  53.     public function findUserIsNotDelete()
  54.     {
  55.         return $this->createQueryBuilder('u')
  56.                     ->andWhere('u.isDelete =:etat')
  57.                     ->setParameter('etat'false)
  58.                     ->orderBy('u.id','DESC')
  59.                     ->getQuery()
  60.                     ->getResult();
  61.     }
  62.     // /**
  63.     //  * @return User[] Returns an array of User objects
  64.     //  */
  65.     /*
  66.     public function findByExampleField($value)
  67.     {
  68.         return $this->createQueryBuilder('u')
  69.             ->andWhere('u.exampleField = :val')
  70.             ->setParameter('val', $value)
  71.             ->orderBy('u.id', 'ASC')
  72.             ->setMaxResults(10)
  73.             ->getQuery()
  74.             ->getResult()
  75.         ;
  76.     }
  77.     */
  78.     /*
  79.     public function findOneBySomeField($value): ?User
  80.     {
  81.         return $this->createQueryBuilder('u')
  82.             ->andWhere('u.exampleField = :val')
  83.             ->setParameter('val', $value)
  84.             ->getQuery()
  85.             ->getOneOrNullResult()
  86.         ;
  87.     }
  88.     */
  89. }