Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/ApiKeyRepository.php
7459 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\User;
6
use Pterodactyl\Models\ApiKey;
7
use Illuminate\Support\Collection;
8
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
9
10
class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInterface
11
{
12
/**
13
* Return the model backing this repository.
14
*/
15
public function model(): string
16
{
17
return ApiKey::class;
18
}
19
20
/**
21
* Get all the account API keys that exist for a specific user.
22
*/
23
public function getAccountKeys(User $user): Collection
24
{
25
return $this->getBuilder()->where('user_id', $user->id)
26
->where('key_type', ApiKey::TYPE_ACCOUNT)
27
->get($this->getColumns());
28
}
29
30
/**
31
* Get all the application API keys that exist for a specific user.
32
*/
33
public function getApplicationKeys(User $user): Collection
34
{
35
return $this->getBuilder()->where('user_id', $user->id)
36
->where('key_type', ApiKey::TYPE_APPLICATION)
37
->get($this->getColumns());
38
}
39
40
/**
41
* Delete an account API key from the panel for a specific user.
42
*/
43
public function deleteAccountKey(User $user, string $identifier): int
44
{
45
return $this->getBuilder()->where('user_id', $user->id)
46
->where('key_type', ApiKey::TYPE_ACCOUNT)
47
->where('identifier', $identifier)
48
->delete();
49
}
50
51
/**
52
* Delete an application API key from the panel for a specific user.
53
*/
54
public function deleteApplicationKey(User $user, string $identifier): int
55
{
56
return $this->getBuilder()->where('user_id', $user->id)
57
->where('key_type', ApiKey::TYPE_APPLICATION)
58
->where('identifier', $identifier)
59
->delete();
60
}
61
}
62
63