2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
namespace openvk\Web\Models\Repositories;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
use openvk\Web\Models\Entities\PasswordReset;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
use Nette\Database\Table\ActiveRow;
|
|
|
|
|
|
|
|
class Restores
|
|
|
|
{
|
|
|
|
private $context;
|
|
|
|
private $restores;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function __construct()
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
|
|
$this->restores = $this->context->table("password_resets");
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function toPasswordReset(?ActiveRow $ar): ?PasswordReset
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
return is_null($ar) ? null : new PasswordReset($ar);
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getByToken(string $token): ?PasswordReset
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return $this->toPasswordReset($this->restores->where("key", $token)->fetch());
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getLatestByUser(User $user): ?PasswordReset
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return $this->toPasswordReset($this->restores->where("profile", $user->getId())->order("timestamp DESC")->fetch());
|
|
|
|
}
|
|
|
|
}
|