Skip to content

Commit 5d56865

Browse files
authored
Update ApiKeyController.php
1 parent 804982c commit 5d56865

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

src/Http/Controllers/ApiKeyController.php

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ class ApiKeyController extends ApplicationApiController
1919
/**
2020
* @var \Pterodactyl\Services\Api\KeyCreationService
2121
*/
22-
private $keyCreationService;
22+
//private $keyCreationService;
2323

2424
/**
2525
* @var \Illuminate\Contracts\Encryption\Encrypter
2626
*/
27-
private $encrypter;
27+
//private $encrypter;
2828

2929
/**
3030
* @var \Pterodactyl\Repositories\Eloquent\ApiKeyRepository
3131
*/
32-
private $repository;
32+
//private $repository;
3333

3434
/**
3535
* ApiKeyController constructor.
3636
*/
37-
public function __construct(
38-
Encrypter $encrypter,
39-
KeyCreationService $keyCreationService,
40-
ApiKeyRepository $repository
41-
) {
42-
parent::__construct();
37+
//public function __construct(
38+
// Encrypter $encrypter,
39+
// KeyCreationService $keyCreationService,
40+
// ApiKeyRepository $repository
41+
//) {
42+
// parent::__construct();
4343

44-
$this->encrypter = $encrypter;
45-
$this->keyCreationService = $keyCreationService;
46-
$this->repository = $repository;
47-
}
44+
// $this->encrypter = $encrypter;
45+
// $this->keyCreationService = $keyCreationService;
46+
// $this->repository = $repository;
47+
//}
4848

4949
/**
5050
* Returns all of the API keys that exist for the given client.
@@ -68,16 +68,22 @@ public function index(GetUsersApiKeysRequest $request, User $user)
6868
*/
6969
public function store(StoreApiKeyRequest $request, User $user)
7070
{
71-
$key = $this->keyCreationService->setKeyType(ApiKey::TYPE_ACCOUNT)->handle([
72-
'user_id' => $user->id,
73-
'memo' => $request->input('description'),
74-
'allowed_ips' => $request->input('allowed_ips') ?? [],
75-
]);
71+
//$key = $this->keyCreationService->setKeyType(ApiKey::TYPE_ACCOUNT)->handle([
72+
// 'user_id' => $user->id,
73+
// 'memo' => $request->input('description'),
74+
// 'allowed_ips' => $request->input('allowed_ips') ?? [],
75+
//]);
7676

77+
$token = $user->createToken(
78+
$request->input('description'),
79+
$request->input('allowed_ips')
80+
);
81+
7782
return $this->fractal->item($key)
7883
->transformWith($this->getTransformer(ApiKeyTransformer::class))
7984
->addMeta([
80-
'secret_token' => $this->encrypter->decrypt($key->token),
85+
//'secret_token' => $this->encrypter->decrypt($key->token),
86+
'secret_token' => $token->plainTextToken
8187
])
8288
->toArray();
8389
}
@@ -89,15 +95,18 @@ public function store(StoreApiKeyRequest $request, User $user)
8995
*/
9096
public function delete(GetUsersApiKeysRequest $request, User $user, string $identifier)
9197
{
92-
$response = $this->repository->deleteWhere([
93-
'key_type' => ApiKey::TYPE_ACCOUNT,
94-
'user_id' => $user->id,
95-
'identifier' => $identifier,
96-
]);
98+
//$response = $this->repository->deleteWhere([
99+
// 'key_type' => ApiKey::TYPE_ACCOUNT,
100+
// 'user_id' => $user->id,
101+
// 'identifier' => $identifier,
102+
//]);
97103

98-
if (!$response) {
99-
throw new NotFoundHttpException();
100-
}
104+
$key = $user->apiKeys()
105+
->where('key_type', ApiKey::TYPE_ACCOUNT)
106+
->where('identifier', $identifier)
107+
->firstOrFail();
108+
109+
$key->delete();
101110

102111
return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT);
103112
}

0 commit comments

Comments
 (0)