diff --git a/src/Dto/UserTokenLoginDto.php b/src/Dto/UserTokenLoginDto.php index 2c621a3..5befd58 100644 --- a/src/Dto/UserTokenLoginDto.php +++ b/src/Dto/UserTokenLoginDto.php @@ -13,23 +13,20 @@ use Symfony\Component\Validator\Constraints as Assert; final class UserTokenLoginDto { /** - * The username of the User to be authenticated. + * The identifier (email, username) of the User to be authenticated. */ #[Assert\NotBlank()] - #[Assert\Length(min: 4, max: 30)] - #[Assert\Regex('/^[a-z0-9_-]+$/')] - public readonly string $username; + public readonly string $identifier; /** * The password of the User to be authenticated. */ #[Assert\NotBlank()] - #[Assert\Length(min: 12)] public readonly string $password; - public function __construct(string $username, string $password) + public function __construct(string $identifier, string $password) { - $this->username = $username; + $this->identifier = $identifier; $this->password = $password; } } diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 9bc97fa..67b3fee 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -41,6 +41,21 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader $this->getEntityManager()->flush(); } + /** + * Find an User by any of it's unique properties + * @param string $identifier An id, email or username + */ + public function findOneByIdentifier(string $identifier): ?User + { + return $this->createQueryBuilder('u') + ->andWhere('u.id = :val') + ->orWhere('u.email = :val') + ->orWhere('u.username = :val') + ->setParameter('val', $identifier) + ->getQuery() + ->getOneOrNullResult(); + } + public function findOneByAccounting(Accounting $accounting): ?User { return $this->createQueryBuilder('u')