|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gbere\SimpleAuth\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
8
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
9
|
|
|
use Gbere\SimpleAuth\Entity\AdminUser; |
|
10
|
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
|
11
|
|
|
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; |
|
12
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @method AdminUser|null find($id, $lockMode = null, $lockVersion = null) |
|
16
|
|
|
* @method AdminUser|null findOneBy(array $criteria, array $orderBy = null) |
|
17
|
|
|
* @method AdminUser[] findAll() |
|
18
|
|
|
* @method AdminUser[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
19
|
|
|
*/ |
|
20
|
|
|
class AdminRepository extends ServiceEntityRepository implements PasswordUpgraderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function __construct(ManagerRegistry $registry) |
|
23
|
|
|
{ |
|
24
|
|
|
parent::__construct($registry, AdminUser::class); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Used to upgrade (rehash) the user's password automatically over time. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function upgradePassword(UserInterface $user, string $newEncodedPassword): void |
|
31
|
|
|
{ |
|
32
|
|
|
if (!$user instanceof AdminUser) { |
|
33
|
|
|
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$user->setPassword($newEncodedPassword); |
|
37
|
|
|
$this->_em->persist($user); |
|
38
|
|
|
$this->_em->flush(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// /** |
|
42
|
|
|
// * @return User[] Returns an array of User objects |
|
43
|
|
|
// */ |
|
44
|
|
|
/* |
|
45
|
|
|
public function findByExampleField($value) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->createQueryBuilder('u') |
|
48
|
|
|
->andWhere('u.exampleField = :val') |
|
49
|
|
|
->setParameter('val', $value) |
|
50
|
|
|
->orderBy('u.id', 'ASC') |
|
51
|
|
|
->setMaxResults(10) |
|
52
|
|
|
->getQuery() |
|
53
|
|
|
->getResult() |
|
54
|
|
|
; |
|
55
|
|
|
} |
|
56
|
|
|
*/ |
|
57
|
|
|
|
|
58
|
|
|
/* |
|
59
|
|
|
public function findOneBySomeField($value): ?User |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->createQueryBuilder('u') |
|
62
|
|
|
->andWhere('u.exampleField = :val') |
|
63
|
|
|
->setParameter('val', $value) |
|
64
|
|
|
->getQuery() |
|
65
|
|
|
->getOneOrNullResult() |
|
66
|
|
|
; |
|
67
|
|
|
} |
|
68
|
|
|
*/ |
|
69
|
|
|
} |
|
70
|
|
|
|