misc_pterodactyl-panel/app/Repositories/Eloquent/ApiKeyRepository.php

64 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\User;
2018-01-14 18:06:15 +00:00
use Pterodactyl\Models\ApiKey;
use Illuminate\Support\Collection;
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInterface
{
/**
* Return the model backing this repository.
*
* @return string
*/
public function model()
{
2018-01-14 18:06:15 +00:00
return ApiKey::class;
}
/**
* Get all of the account API keys that exist for a specific user.
*/
public function getAccountKeys(User $user): Collection
{
return $this->getBuilder()->where('user_id', $user->id)
->where('key_type', ApiKey::TYPE_ACCOUNT)
->get($this->getColumns());
}
2018-01-19 03:36:15 +00:00
/**
* Get all of the application API keys that exist for a specific user.
*/
public function getApplicationKeys(User $user): Collection
{
return $this->getBuilder()->where('user_id', $user->id)
->where('key_type', ApiKey::TYPE_APPLICATION)
->get($this->getColumns());
}
/**
* Delete an account API key from the panel for a specific user.
*/
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();
}
2018-01-19 03:36:15 +00:00
/**
* Delete an application API key from the panel for a specific user.
*/
public function deleteApplicationKey(User $user, string $identifier): int
{
return $this->getBuilder()->where('user_id', $user->id)
->where('key_type', ApiKey::TYPE_APPLICATION)
->where('identifier', $identifier)
->delete();
}
}