vendor/umbrella2/adminbundle/src/Service/UserManager.php line 27

Open in your IDE?
  1. <?php
  2. namespace Umbrella\AdminBundle\Service;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\Persistence\ObjectRepository;
  5. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  6. use Umbrella\AdminBundle\Entity\BaseAdminUser;
  7. use Umbrella\AdminBundle\UmbrellaAdminConfiguration;
  8. class UserManager implements UserManagerInterface
  9. {
  10.     protected EntityManagerInterface $em;
  11.     protected UserPasswordHasherInterface $passwordHasher;
  12.     protected string $class;
  13.     protected ObjectRepository $repo;
  14.     /**
  15.      * UserManager constructor.
  16.      */
  17.     public function __construct(EntityManagerInterface $emUserPasswordHasherInterface $passwordHasherUmbrellaAdminConfiguration $config)
  18.     {
  19.         $this->em $em;
  20.         $this->passwordHasher $passwordHasher;
  21.         $this->class $config->userClass();
  22.         $this->repo $this->em->getRepository($this->class);
  23.     }
  24.     public function create(): BaseAdminUser
  25.     {
  26.         return new $this->class();
  27.     }
  28.     public function find($id): ?BaseAdminUser
  29.     {
  30.         return $this->repo->find($id);
  31.     }
  32.     public function findOneBy(array $criteria): ?BaseAdminUser
  33.     {
  34.         return $this->repo->findOneBy($criteria);
  35.     }
  36.     public function findOneByEmail(string $email): ?BaseAdminUser
  37.     {
  38.         return $this->findOneBy(['email' => $email]);
  39.     }
  40.     public function findOneByConfirmationToken(string $confirmationToken): ?BaseAdminUser
  41.     {
  42.         return $this->findOneBy(['confirmationToken' => $confirmationToken]);
  43.     }
  44.     public function updatePassword(BaseAdminUser $user): void
  45.     {
  46.         if (!empty($user->plainPassword)) {
  47.             $user->setPassword($this->passwordHasher->hashPassword($user$user->plainPassword));
  48.             // erase confirmation token if password was updated
  49.             $user->passwordRequestedAt null;
  50.             $user->confirmationToken null;
  51.             $user->eraseCredentials();
  52.         }
  53.     }
  54.     public function update(BaseAdminUser $user): void
  55.     {
  56.         $this->updatePassword($user);
  57.         $this->em->persist($user);
  58.         $this->em->flush();
  59.     }
  60.     public function delete(BaseAdminUser $user): void
  61.     {
  62.         $this->em->remove($user);
  63.         $this->em->flush();
  64.     }
  65.     public function getClass(): string
  66.     {
  67.         return $this->class;
  68.     }
  69. }