mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-22 01:49:05 +02:00
Added an mechanism to reset passwords via mail.
This commit is contained in:
parent
0716b8ff93
commit
6a0d027675
20 changed files with 2373 additions and 64 deletions
|
@ -26,6 +26,7 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Mapping;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||
|
||||
/**
|
||||
|
@ -44,7 +45,7 @@ class UserRepository extends EntityRepository
|
|||
*
|
||||
* @return User|null
|
||||
*/
|
||||
public function getAnonymousUser()
|
||||
public function getAnonymousUser() : ?User
|
||||
{
|
||||
if ($this->anonymous_user === null) {
|
||||
$this->anonymous_user = $this->findOneBy([
|
||||
|
@ -54,4 +55,29 @@ class UserRepository extends EntityRepository
|
|||
|
||||
return $this->anonymous_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a user by its name or its email. Useful for login or password reset purposes.
|
||||
* @param string $name_or_password The username or the email of the user that should be found
|
||||
* @return User|null The user if it is existing, null if no one matched the criteria
|
||||
*/
|
||||
public function findByEmailOrName(string $name_or_password) : ?User
|
||||
{
|
||||
if (empty($name_or_password)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder('u');
|
||||
$qb->select('u')
|
||||
->where('u.name = (:name)')
|
||||
->orWhere('u.email = (:email)');
|
||||
|
||||
$qb->setParameters(['email' => $name_or_password, 'name' => $name_or_password]);
|
||||
|
||||
try {
|
||||
return $qb->getQuery()->getOneOrNullResult();
|
||||
} catch (NonUniqueResultException $exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue