46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Core\Database;
|
|
|
|
class PasswordReset
|
|
{
|
|
private Database $database;
|
|
|
|
public function __construct(Database $database)
|
|
{
|
|
$this->database = $database;
|
|
}
|
|
|
|
public function create(array $data): int
|
|
{
|
|
return $this->database->insert('password_resets', $data);
|
|
}
|
|
|
|
public function findByToken(string $token): ?array
|
|
{
|
|
return $this->database->fetch(
|
|
"SELECT * FROM password_resets WHERE token = :token",
|
|
['token' => $token]
|
|
);
|
|
}
|
|
|
|
public function delete(int $id): bool
|
|
{
|
|
return $this->database->delete('password_resets', 'id = :id', ['id' => $id]) > 0;
|
|
}
|
|
|
|
public function deleteExpired(): int
|
|
{
|
|
return $this->database->query(
|
|
"DELETE FROM password_resets WHERE expires_at < NOW()"
|
|
)->rowCount();
|
|
}
|
|
|
|
public function deleteByUserId(int $userId): int
|
|
{
|
|
return $this->database->delete('password_resets', 'user_id = :user_id', ['user_id' => $userId]);
|
|
}
|
|
}
|