2017-07-08 19:07:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
2018-01-14 19:30:55 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2018-01-14 18:06:15 +00:00
|
|
|
use Pterodactyl\Models\ApiKey;
|
2018-01-14 19:30:55 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2017-07-08 19:07:51 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
|
|
|
|
|
|
|
|
class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-07-08 19:07:51 +00:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
2018-01-14 18:06:15 +00:00
|
|
|
return ApiKey::class;
|
2017-07-08 19:07:51 +00:00
|
|
|
}
|
2017-12-03 20:29:14 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-14 19:30:55 +00:00
|
|
|
* Get all of the account API keys that exist for a specific user.
|
2017-12-03 20:29:14 +00:00
|
|
|
*
|
2018-01-14 19:30:55 +00:00
|
|
|
* @param \Pterodactyl\Models\User $user
|
|
|
|
* @return \Illuminate\Support\Collection
|
2017-12-03 20:29:14 +00:00
|
|
|
*/
|
2018-01-14 19:30:55 +00:00
|
|
|
public function getAccountKeys(User $user): Collection
|
2017-12-03 20:29:14 +00:00
|
|
|
{
|
2018-01-14 19:30:55 +00:00
|
|
|
return $this->getBuilder()->where('user_id', $user->id)
|
|
|
|
->where('key_type', ApiKey::TYPE_ACCOUNT)
|
|
|
|
->get($this->getColumns());
|
|
|
|
}
|
2017-12-03 20:29:14 +00:00
|
|
|
|
2018-01-14 19:30:55 +00:00
|
|
|
/**
|
|
|
|
* Delete an account API key from the panel for a specific user.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\User $user
|
|
|
|
* @param string $identifier
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function deleteAccountKey(User $user, string $identifier): int
|
|
|
|
{
|
|
|
|
return $this->getBuilder()->where('user_id', $user->id)
|
|
|
|
->where('key_type', ApiKey::TYPE_ACCOUNT)
|
|
|
|
->where('identifier', $identifier)
|
|
|
|
->delete();
|
2017-12-03 20:29:14 +00:00
|
|
|
}
|
2017-07-08 19:07:51 +00:00
|
|
|
}
|