Skip to content

Commit e045ef4

Browse files
committed
Should wrap up the base landing page stuff for accounts, next step is server rendering
1 parent 67ac36f commit e045ef4

32 files changed

+1219
-313
lines changed

.php_cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ return PhpCsFixer\Config::create()
2525
'declare_equal_normalize' => ['space' => 'single'],
2626
'heredoc_to_nowdoc' => true,
2727
'linebreak_after_opening_tag' => true,
28+
'method_argument_space' => [
29+
'ensure_fully_multiline' => false,
30+
'keep_multiple_spaces_after_comma' => false,
31+
],
2832
'new_with_braces' => false,
2933
'no_alias_functions' => true,
3034
'no_multiline_whitespace_before_semicolons' => true,

app/Contracts/Repository/Daemon/ServerRepositoryInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,11 @@ public function unsuspend();
8888
* @return \Psr\Http\Message\ResponseInterface
8989
*/
9090
public function delete();
91+
92+
/**
93+
* Return detials on a specific server.
94+
*
95+
* @return \Psr\Http\Message\ResponseInterface
96+
*/
97+
public function details();
9198
}

app/Contracts/Repository/RepositoryInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ public function withoutFresh();
7474
*
7575
* @param array $fields
7676
* @param bool $validate
77+
* @param bool $force
7778
* @return mixed
7879
*
7980
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
8081
*/
81-
public function create(array $fields, $validate = true);
82+
public function create(array $fields, $validate = true, $force = false);
8283

8384
/**
8485
* Delete a given record from the database.

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,33 @@ public function getWithDatabases($id);
8787
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
8888
*/
8989
public function getDaemonServiceData($id);
90+
91+
/**
92+
* Return an array of server IDs that a given user can access based on owner and subuser permissions.
93+
*
94+
* @param int $user
95+
* @return array
96+
*/
97+
public function getUserAccessServers($user);
98+
99+
/**
100+
* Return a paginated list of servers that a user can access at a given level.
101+
*
102+
* @param int $user
103+
* @param string $level
104+
* @param bool $admin
105+
* @param array $relations
106+
* @return \Illuminate\Pagination\LengthAwarePaginator
107+
*/
108+
public function filterUserAccessServers($user, $admin = false, $level = 'all', array $relations = []);
109+
110+
/**
111+
* Return a server by UUID.
112+
*
113+
* @param string $uuid
114+
* @return \Illuminate\Database\Eloquent\Collection
115+
*
116+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
117+
*/
118+
public function getByUuid($uuid);
90119
}
Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
/**
2+
/*
33
* Pterodactyl - Panel
44
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
55
*
@@ -22,50 +22,24 @@
2222
* SOFTWARE.
2323
*/
2424

25-
namespace Pterodactyl\Http\Controllers\Base;
25+
namespace Pterodactyl\Contracts\Repository;
2626

27-
use Auth;
28-
use Session;
29-
use Illuminate\Http\Request;
30-
use Pterodactyl\Models\User;
31-
use Pterodactyl\Http\Controllers\Controller;
32-
33-
class LanguageController extends Controller
27+
interface SessionRepositoryInterface extends RepositoryInterface
3428
{
3529
/**
36-
* A list of supported languages on the panel.
30+
* Delete a session for a given user.
3731
*
38-
* @var array
32+
* @param int $user
33+
* @param int $session
34+
* @return null|int
3935
*/
40-
protected $languages = [
41-
'de' => 'German',
42-
'en' => 'English',
43-
'et' => 'Estonian',
44-
'nb' => 'Norwegian',
45-
'nl' => 'Dutch',
46-
'pt' => 'Portuguese',
47-
'ro' => 'Romanian',
48-
'ru' => 'Russian',
49-
];
36+
public function deleteUserSession($user, $session);
5037

5138
/**
52-
* Sets the language for a user.
39+
* Return all of the active sessions for a user.
5340
*
54-
* @param \Illuminate\Http\Request $request
55-
* @param string $language
56-
* @return \Illuminate\Http\RedirectResponse
41+
* @param int $user
42+
* @return \Illuminate\Support\Collection
5743
*/
58-
public function setLanguage(Request $request, $language)
59-
{
60-
if (array_key_exists($language, $this->languages)) {
61-
if (Auth::check()) {
62-
$user = User::findOrFail(Auth::user()->id);
63-
$user->language = $language;
64-
$user->save();
65-
}
66-
Session::put('applocale', $language);
67-
}
68-
69-
return redirect()->back();
70-
}
44+
public function getUserSessions($user);
7145
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Http\Base;
26+
27+
use Pterodactyl\Exceptions\DisplayException;
28+
29+
class InvalidPasswordProvidedException extends DisplayException
30+
{
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Exceptions\Service\User;
26+
27+
class TwoFactorAuthenticationTokenInvalid extends \Exception
28+
{
29+
}

app/Http/Controllers/Base/APIController.php

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727

2828
use Illuminate\Http\Request;
2929
use Prologue\Alerts\AlertsMessageBag;
30+
use Pterodactyl\Http\Requests\Base\ApiKeyFormRequest;
3031
use Pterodactyl\Models\APIPermission;
31-
use Pterodactyl\Services\ApiKeyService;
3232
use Pterodactyl\Http\Controllers\Controller;
33-
use Pterodactyl\Http\Requests\ApiKeyRequest;
34-
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
3533
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
34+
use Pterodactyl\Services\Api\KeyCreationService;
3635

3736
class APIController extends Controller
3837
{
@@ -42,37 +41,39 @@ class APIController extends Controller
4241
protected $alert;
4342

4443
/**
45-
* @var \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface
44+
* @var \Pterodactyl\Services\Api\KeyCreationService
4645
*/
47-
protected $repository;
46+
protected $keyService;
4847

4948
/**
50-
* @var \Pterodactyl\Services\ApiKeyService
49+
* @var \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface
5150
*/
52-
protected $service;
51+
protected $repository;
5352

5453
/**
5554
* APIController constructor.
5655
*
5756
* @param \Prologue\Alerts\AlertsMessageBag $alert
5857
* @param \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface $repository
59-
* @param \Pterodactyl\Services\ApiKeyService $service
58+
* @param \Pterodactyl\Services\Api\KeyCreationService $keyService
6059
*/
6160
public function __construct(
6261
AlertsMessageBag $alert,
6362
ApiKeyRepositoryInterface $repository,
64-
ApiKeyService $service
63+
KeyCreationService $keyService
6564
) {
6665
$this->alert = $alert;
66+
$this->keyService = $keyService;
6767
$this->repository = $repository;
68-
$this->service = $service;
6968
}
7069

7170
/**
7271
* Display base API index page.
7372
*
7473
* @param \Illuminate\Http\Request $request
7574
* @return \Illuminate\View\View
75+
*
76+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
7677
*/
7778
public function index(Request $request)
7879
{
@@ -84,45 +85,41 @@ public function index(Request $request)
8485
/**
8586
* Display API key creation page.
8687
*
88+
* @param \Illuminate\Http\Request $request
8789
* @return \Illuminate\View\View
8890
*/
89-
public function create()
91+
public function create(Request $request)
9092
{
9193
return view('base.api.new', [
9294
'permissions' => [
9395
'user' => collect(APIPermission::CONST_PERMISSIONS)->pull('_user'),
94-
'admin' => collect(APIPermission::CONST_PERMISSIONS)->except('_user')->toArray(),
96+
'admin' => ! $request->user()->root_admin ?: collect(APIPermission::CONST_PERMISSIONS)->except('_user')->toArray(),
9597
],
9698
]);
9799
}
98100

99101
/**
100102
* Handle saving new API key.
101103
*
102-
* @param \Pterodactyl\Http\Requests\ApiKeyRequest $request
104+
* @param \Pterodactyl\Http\Requests\Base\ApiKeyFormRequest $request
103105
* @return \Illuminate\Http\RedirectResponse
104-
*
105106
* @throws \Exception
106107
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
107108
*/
108-
public function store(ApiKeyRequest $request)
109+
public function store(ApiKeyFormRequest $request)
109110
{
110111
$adminPermissions = [];
111-
if ($request->user()->isRootAdmin()) {
112+
if ($request->user()->root_admin) {
112113
$adminPermissions = $request->input('admin_permissions') ?? [];
113114
}
114115

115-
$secret = $this->service->create([
116+
$secret = $this->keyService->handle([
116117
'user_id' => $request->user()->id,
117118
'allowed_ips' => $request->input('allowed_ips'),
118119
'memo' => $request->input('memo'),
119-
], $request->input('permissions') ?? [], $adminPermissions);
120+
], $request->input('permissions', []), $adminPermissions);
120121

121-
$this->alert->success(
122-
"An API Key-Pair has successfully been generated. The API secret
123-
for this public key is shown below and will not be shown again.
124-
<br /><br /><code>{$secret}</code>"
125-
)->flash();
122+
$this->alert->success(trans('base.api.index.keypair_created', ['token' => $secret]))->flash();
126123

127124
return redirect()->route('account.api');
128125
}
@@ -136,16 +133,10 @@ public function store(ApiKeyRequest $request)
136133
*/
137134
public function revoke(Request $request, $key)
138135
{
139-
try {
140-
$key = $this->repository->withColumns('id')->findFirstWhere([
141-
['user_id', '=', $request->user()->id],
142-
['public', $key],
143-
]);
144-
145-
$this->service->revoke($key->id);
146-
} catch (RecordNotFoundException $ex) {
147-
return abort(404);
148-
}
136+
$this->repository->deleteWhere([
137+
['user_id', '=', $request->user()->id],
138+
['public', '=', $key],
139+
]);
149140

150141
return response('', 204);
151142
}

0 commit comments

Comments
 (0)