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 findEmailUser($id)
  54.     {
  55.         return $this->createQueryBuilder('u')
  56.                     ->select('u.email')
  57.                     ->andWhere('u.id =:id')
  58.                     ->setParameter('id'$id)
  59.                     ->getQuery()
  60.                     ->getOneOrNullResult();
  61.     }
  62.     public function findUserIsNotDelete()
  63.     {
  64.         return $this->createQueryBuilder('u')
  65.                     ->andWhere('u.isDelete =:etat')
  66.                     ->setParameter('etat'false)
  67.                     ->orderBy('u.id','DESC')
  68.                     ->getQuery()
  69.                     ->getResult();
  70.     }
  71.     // /**
  72.     //  * @return User[] Returns an array of User objects
  73.     //  */
  74.     /*
  75.     public function findByExampleField($value)
  76.     {
  77.         return $this->createQueryBuilder('u')
  78.             ->andWhere('u.exampleField = :val')
  79.             ->setParameter('val', $value)
  80.             ->orderBy('u.id', 'ASC')
  81.             ->setMaxResults(10)
  82.             ->getQuery()
  83.             ->getResult()
  84.         ;
  85.     }
  86.     */
  87.     /*
  88.     public function findOneBySomeField($value): ?User
  89.     {
  90.         return $this->createQueryBuilder('u')
  91.             ->andWhere('u.exampleField = :val')
  92.             ->setParameter('val', $value)
  93.             ->getQuery()
  94.             ->getOneOrNullResult()
  95.         ;
  96.     }
  97.     */
  98. }