2020-07-05 00:03:56 +02:00
|
|
|
<?php namespace MapGuesser\Repository;
|
|
|
|
|
2020-07-05 16:37:37 +02:00
|
|
|
use DateTime;
|
|
|
|
use Generator;
|
2020-07-05 00:03:56 +02:00
|
|
|
use MapGuesser\Database\Query\Select;
|
|
|
|
use MapGuesser\PersistentData\Model\User;
|
|
|
|
use MapGuesser\PersistentData\Model\UserPasswordResetter;
|
|
|
|
use MapGuesser\PersistentData\PersistentDataManager;
|
|
|
|
|
|
|
|
class UserPasswordResetterRepository
|
|
|
|
{
|
|
|
|
private PersistentDataManager $pdm;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->pdm = new PersistentDataManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getById(int $userConfirmationId): ?UserPasswordResetter
|
|
|
|
{
|
|
|
|
return $this->pdm->selectFromDbById($userConfirmationId, UserPasswordResetter::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getByToken(string $token): ?UserPasswordResetter
|
|
|
|
{
|
|
|
|
$select = new Select(\Container::$dbConnection);
|
|
|
|
$select->where('token', '=', $token);
|
|
|
|
|
|
|
|
return $this->pdm->selectFromDb($select, UserPasswordResetter::class);
|
|
|
|
}
|
|
|
|
|
2020-07-05 13:22:22 +02:00
|
|
|
public function getByUser(User $user): ?UserPasswordResetter
|
2020-07-05 00:03:56 +02:00
|
|
|
{
|
|
|
|
$select = new Select(\Container::$dbConnection);
|
|
|
|
$select->where('user_id', '=', $user->getId());
|
|
|
|
|
2020-07-05 13:22:22 +02:00
|
|
|
return $this->pdm->selectFromDb($select, UserPasswordResetter::class);
|
2020-07-05 00:03:56 +02:00
|
|
|
}
|
2020-07-05 16:37:37 +02:00
|
|
|
|
|
|
|
public function getAllExpired(): Generator
|
|
|
|
{
|
|
|
|
$select = new Select(\Container::$dbConnection);
|
|
|
|
$select->where('expires', '<', (new DateTime())->format('Y-m-d H:i:s'));
|
|
|
|
|
|
|
|
yield from $this->pdm->selectMultipleFromDb($select, UserPasswordResetter::class);
|
|
|
|
}
|
2020-07-05 00:03:56 +02:00
|
|
|
}
|