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.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-06-25 20:31:50 +00:00
|
|
|
*/
|
2017-08-31 02:11:14 +00:00
|
|
|
public function model()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all of the active sessions for a user.
|
|
|
|
*
|
|
|
|
* @param int $user
|
|
|
|
* @return \Illuminate\Support\Collection
|
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.
|
|
|
|
*
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param int $user
|
2018-02-03 18:18:18 +00:00
|
|
|
* @param string $session
|
2020-06-28 22:43:44 +00:00
|
|
|
* @return int|null
|
2017-08-31 02:11:14 +00:00
|
|
|
*/
|
2018-02-03 18:18:18 +00:00
|
|
|
public function deleteUserSession(int $user, string $session)
|
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
|
|
|
}
|
|
|
|
}
|