2017-06-25 20:31:50 +00:00
|
|
|
<?php
|
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2017-06-25 20:31:50 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
use Pterodactyl\Models\Session;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2017-08-31 02:11:14 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\SessionRepositoryInterface;
|
2017-06-25 20:31:50 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
class SessionRepository extends EloquentRepository implements SessionRepositoryInterface
|
2017-06-25 20:31:50 +00:00
|
|
|
{
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
2017-06-25 20:31:50 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function model(): string
|
2017-06-25 20:31:50 +00:00
|
|
|
{
|
2017-08-31 02:11:14 +00:00
|
|
|
return Session::class;
|
2017-06-25 20:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Return all the active sessions for a user.
|
2017-06-25 20:31:50 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getUserSessions(int $user): Collection
|
2017-06-25 20:31:50 +00:00
|
|
|
{
|
2017-08-31 02:11:14 +00:00
|
|
|
return $this->getBuilder()->where('user_id', $user)->get($this->getColumns());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Delete a session for a given user.
|
2017-08-31 02:11:14 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function deleteUserSession(int $user, string $session): ?int
|
2017-08-31 02:11:14 +00:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->where('user_id', $user)->where('id', $session)->delete();
|
2017-06-25 20:31:50 +00:00
|
|
|
}
|
|
|
|
}
|