Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
Add key when authenticated but no key is added to account #1 close
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvan Watchman committed Jun 18, 2019
1 parent 817cf55 commit db46d54
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Controllers/Api/User/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
use Pterodactyl\Services\Api\KeyCreationService;
use Pterodactyl\Models\ApiKey;

class LoginController extends Controller
{
Expand All @@ -20,10 +22,16 @@ class LoginController extends Controller
*/
private $service;

public function __construct(UserRepositoryInterface $repository, ApiKeyRepositoryInterface $apiKeyRepository) {
/**
* @var \Pterodactyl\Services\Api\KeyCreationService
*/
private $keyCreationService;

public function __construct(UserRepositoryInterface $repository, ApiKeyRepositoryInterface $apiKeyRepository, KeyCreationService $keyCreationService) {
parent::__construct();
$this->repository = $repository;
$this->apiKeyRepository = $apiKeyRepository;
$this->keyCreationService = $keyCreationService;
}

public function login(Request $req) {
Expand All @@ -49,6 +57,15 @@ public function login(Request $req) {
'token' => $key->identifier . decrypt($key->token),
];
}

if(!$keys->count()) {
$this->keyCreationService->setKeyType(ApiKey::TYPE_ACCOUNT)->handle([
'memo' => 'Pterodactyl App key',
'allowed_ips' => null,
'user_id' => $user->id
]);
}

return response()->json([
'object' => 'list',
'data' => $data
Expand Down

0 comments on commit db46d54

Please sign in to comment.