Files
TijdVoorDeTest/src/Repository/UserRepository.php
Marijn Doeve b66d2f9e86
Some checks failed
CI / Tests (push) Failing after 35s
CI / Deploy (push) Has been skipped
Refactor entities and codebase for native property usage
- Replaced getters/setters with direct property access across entities and repositories.
- Added and configured `martin-georgiev/postgresql-for-doctrine` for PostgreSQL enhancements.
- Updated Doctrine configuration with types, mappings, and JSONB query functions.
- Removed unused `EliminationService` and related YAML configurations.
2025-10-08 20:50:33 +02:00

42 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tvdt\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
use Tvdt\Entity\User;
/** @extends ServiceEntityRepository<User> */
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/** Used to upgrade (rehash) the user's password automatically over time.
* @param User $user
* */
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
{
$user->password = $newHashedPassword;
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();
}
public function makeAdmin(string $email): void
{
$user = $this->findOneBy(['email' => $email]);
if (!$user instanceof User) {
throw new \InvalidArgumentException('User not found');
}
$user->roles = ['ROLE_ADMIN'];
$this->getEntityManager()->flush();
}
}