|
5 | 5 | use <?= $entity_full_class_name; ?>; |
6 | 6 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
7 | 7 | use Doctrine\Common\Persistence\ManagerRegistry; |
| 8 | +<?= $with_password_upgrade ? "use Symfony\Component\Security\Core\Exception\UnsupportedUserException;\n" : '' ?> |
| 9 | +<?= $with_password_upgrade ? "use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;\n" : '' ?> |
| 10 | +<?= $with_password_upgrade ? "use Symfony\Component\Security\Core\User\UserInterface;\n" : '' ?> |
8 | 11 |
|
9 | 12 | /** |
10 | 13 | * @method <?= $entity_class_name; ?>|null find($id, $lockMode = null, $lockVersion = null) |
11 | 14 | * @method <?= $entity_class_name; ?>|null findOneBy(array $criteria, array $orderBy = null) |
12 | 15 | * @method <?= $entity_class_name; ?>[] findAll() |
13 | 16 | * @method <?= $entity_class_name; ?>[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
14 | 17 | */ |
15 | | -class <?= $class_name; ?> extends ServiceEntityRepository |
| 18 | +class <?= $class_name; ?> extends ServiceEntityRepository<?= $with_password_upgrade ? " implements PasswordUpgraderInterface\n" : "\n" ?> |
16 | 19 | { |
17 | 20 | public function __construct(ManagerRegistry $registry) |
18 | 21 | { |
19 | 22 | parent::__construct($registry, <?= $entity_class_name; ?>::class); |
20 | 23 | } |
21 | 24 |
|
| 25 | +<?php if ($with_password_upgrade): ?> |
| 26 | + /** |
| 27 | + * Used to upgrade (rehash) the user's password automatically over time. |
| 28 | + */ |
| 29 | + public function upgradePassword(UserInterface $user, string $newEncodedPassword): void |
| 30 | + { |
| 31 | + if (!$user instanceof User) { |
| 32 | + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); |
| 33 | + } |
| 34 | + |
| 35 | + $user->setPassword($newEncodedPassword); |
| 36 | + $this->_em->persist($user); |
| 37 | + $this->_em->flush(); |
| 38 | + } |
| 39 | + |
| 40 | +<?php endif ?> |
22 | 41 | // /** |
23 | 42 | // * @return <?= $entity_class_name ?>[] Returns an array of <?= $entity_class_name ?> objects |
24 | 43 | // */ |
|
0 commit comments