Allow users to be queried by either id, email or username
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user