2021-03-24 12:27:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repository;
|
|
|
|
|
|
|
|
use App\Entity\User;
|
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
|
|
|
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
2022-01-24 22:15:53 +01:00
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
2021-03-24 12:27:07 +01:00
|
|
|
|
|
|
|
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
|
|
|
|
{
|
|
|
|
public function __construct(ManagerRegistry $registry)
|
|
|
|
{
|
|
|
|
parent::__construct($registry, User::class);
|
|
|
|
}
|
|
|
|
|
2022-01-24 22:15:53 +01:00
|
|
|
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newEncodedPassword): void
|
2021-03-24 12:27:07 +01:00
|
|
|
{
|
|
|
|
if (!$user instanceof User) {
|
|
|
|
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$user->setPassword($newEncodedPassword);
|
|
|
|
$this->_em->persist($user);
|
|
|
|
$this->_em->flush();
|
|
|
|
}
|
|
|
|
}
|