Skip to content

Commit c087f64

Browse files
committed
Temporary patch to get user management pages displaying correctly
1 parent 06e5a05 commit c087f64

File tree

6 files changed

+32
-119
lines changed

6 files changed

+32
-119
lines changed

app/Http/Controllers/Admin/UserController.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,11 @@ public function store(UserFormRequest $request)
164164
*/
165165
public function update(UserFormRequest $request, User $user)
166166
{
167-
$this->updateService->setUserLevel(User::USER_LEVEL_ADMIN);
168-
$data = $this->updateService->handle($user, $request->normalize());
169-
170-
if (! empty($data->get('exceptions'))) {
171-
foreach ($data->get('exceptions') as $node => $exception) {
172-
/** @var \GuzzleHttp\Exception\RequestException $exception */
173-
/** @var \GuzzleHttp\Psr7\Response|null $response */
174-
$response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null;
175-
$message = trans('admin/server.exceptions.daemon_exception', [
176-
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
177-
]);
178-
179-
$this->alert->danger(trans('exceptions.users.node_revocation_failed', [
180-
'node' => $node,
181-
'error' => $message,
182-
'link' => route('admin.nodes.view', $node),
183-
]))->flash();
184-
}
185-
}
167+
$this->updateService
168+
->setUserLevel(User::USER_LEVEL_ADMIN)
169+
->handle($user, $request->normalize());
186170

187-
$this->alert->success($this->translator->trans('admin/user.notices.account_updated'))->flash();
171+
$this->alert->success(trans('admin/user.notices.account_updated'))->flash();
188172

189173
return redirect()->route('admin.users.view', $user->id);
190174
}
@@ -193,7 +177,7 @@ public function update(UserFormRequest $request, User $user)
193177
* Get a JSON response of users on the system.
194178
*
195179
* @param \Illuminate\Http\Request $request
196-
* @return \Illuminate\Database\Eloquent\Collection
180+
* @return \Illuminate\Support\Collection
197181
*/
198182
public function json(Request $request)
199183
{

app/Http/Requests/Admin/UserFormRequest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Http\Requests\Admin;
44

55
use Pterodactyl\Models\User;
6+
use Illuminate\Support\Collection;
67

78
class UserFormRequest extends AdminFormRequest
89
{
@@ -12,16 +13,16 @@ class UserFormRequest extends AdminFormRequest
1213
*/
1314
public function rules()
1415
{
15-
$rules = collect(User::getRules());
16-
if ($this->method() === 'PATCH') {
17-
$rules = collect(User::getRulesForUpdate($this->route()->parameter('user')))->merge([
18-
'ignore_connection_error' => ['sometimes', 'nullable', 'boolean'],
19-
]);
20-
}
21-
22-
return $rules->only([
23-
'email', 'username', 'name_first', 'name_last', 'password',
24-
'language', 'ignore_connection_error', 'root_admin',
16+
return Collection::make(
17+
User::getRulesForUpdate($this->route()->parameter('user'))
18+
)->only([
19+
'email',
20+
'username',
21+
'name_first',
22+
'name_last',
23+
'password',
24+
'language',
25+
'root_admin',
2526
])->toArray();
2627
}
2728
}

app/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class User extends Validable implements
158158
'username' => 'required|between:1,255|unique:users,username',
159159
'name_first' => 'required|string|between:1,255',
160160
'name_last' => 'required|string|between:1,255',
161-
'password' => 'required|nullable|string',
161+
'password' => 'sometimes|nullable|string',
162162
'root_admin' => 'boolean',
163163
'language' => 'required|string',
164164
'use_totp' => 'boolean',

app/Services/Users/ToggleTwoFactorService.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
use Carbon\Carbon;
66
use Pterodactyl\Models\User;
77
use PragmaRX\Google2FA\Google2FA;
8-
use Illuminate\Contracts\Config\Repository;
98
use Illuminate\Contracts\Encryption\Encrypter;
109
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1110
use Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid;
1211

1312
class ToggleTwoFactorService
1413
{
15-
/**
16-
* @var \Illuminate\Contracts\Config\Repository
17-
*/
18-
private $config;
19-
2014
/**
2115
* @var \Illuminate\Contracts\Encryption\Encrypter
2216
*/
@@ -37,16 +31,13 @@ class ToggleTwoFactorService
3731
*
3832
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
3933
* @param \PragmaRX\Google2FA\Google2FA $google2FA
40-
* @param \Illuminate\Contracts\Config\Repository $config
4134
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
4235
*/
4336
public function __construct(
4437
Encrypter $encrypter,
4538
Google2FA $google2FA,
46-
Repository $config,
4739
UserRepositoryInterface $repository
4840
) {
49-
$this->config = $config;
5041
$this->encrypter = $encrypter;
5142
$this->google2FA = $google2FA;
5243
$this->repository = $repository;
@@ -60,16 +51,18 @@ public function __construct(
6051
* @param bool|null $toggleState
6152
* @return bool
6253
*
54+
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
55+
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
56+
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
6357
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
6458
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6559
* @throws \Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid
6660
*/
6761
public function handle(User $user, string $token, bool $toggleState = null): bool
6862
{
69-
$window = $this->config->get('pterodactyl.auth.2fa.window');
7063
$secret = $this->encrypter->decrypt($user->totp_secret);
7164

72-
$isValidToken = $this->google2FA->verifyKey($secret, $token, $window);
65+
$isValidToken = $this->google2FA->verifyKey($secret, $token, config()->get('pterodactyl.auth.2fa.window'));
7366

7467
if (! $isValidToken) {
7568
throw new TwoFactorAuthenticationTokenInvalid;

app/Services/Users/UserUpdateService.php

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
namespace Pterodactyl\Services\Users;
44

55
use Pterodactyl\Models\User;
6-
use Illuminate\Support\Collection;
76
use Illuminate\Contracts\Hashing\Hasher;
87
use Pterodactyl\Traits\Services\HasUserLevels;
9-
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
10-
use Pterodactyl\Services\DaemonKeys\RevokeMultipleDaemonKeysService;
8+
use Pterodactyl\Repositories\Eloquent\UserRepository;
119

1210
class UserUpdateService
1311
{
@@ -19,62 +17,43 @@ class UserUpdateService
1917
private $hasher;
2018

2119
/**
22-
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
20+
* @var \Pterodactyl\Repositories\Eloquent\UserRepository
2321
*/
2422
private $repository;
2523

26-
/**
27-
* @var \Pterodactyl\Services\DaemonKeys\RevokeMultipleDaemonKeysService
28-
*/
29-
private $revocationService;
30-
3124
/**
3225
* UpdateService constructor.
3326
*
3427
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
35-
* @param \Pterodactyl\Services\DaemonKeys\RevokeMultipleDaemonKeysService $revocationService
36-
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
28+
* @param \Pterodactyl\Repositories\Eloquent\UserRepository $repository
3729
*/
38-
public function __construct(
39-
Hasher $hasher,
40-
RevokeMultipleDaemonKeysService $revocationService,
41-
UserRepositoryInterface $repository
42-
) {
30+
public function __construct(Hasher $hasher, UserRepository $repository)
31+
{
4332
$this->hasher = $hasher;
4433
$this->repository = $repository;
45-
$this->revocationService = $revocationService;
4634
}
4735

4836
/**
49-
* Update the user model instance. If the user has been removed as an administrator
50-
* revoke all of the authentication tokens that have been assigned to their account.
37+
* Update the user model instance.
5138
*
5239
* @param \Pterodactyl\Models\User $user
5340
* @param array $data
54-
* @return \Illuminate\Support\Collection
41+
* @return \Pterodactyl\Models\User
5542
*
5643
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
5744
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
5845
*/
59-
public function handle(User $user, array $data): Collection
46+
public function handle(User $user, array $data)
6047
{
6148
if (! empty(array_get($data, 'password'))) {
6249
$data['password'] = $this->hasher->make($data['password']);
6350
} else {
6451
unset($data['password']);
6552
}
6653

67-
if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) {
68-
if (array_get($data, 'root_admin', 0) == 0 && $user->root_admin) {
69-
$this->revocationService->handle($user, array_get($data, 'ignore_connection_error', false));
70-
}
71-
} else {
72-
unset($data['root_admin']);
73-
}
54+
/** @var \Pterodactyl\Models\User $response */
55+
$response = $this->repository->update($user->id, $data);
7456

75-
return collect([
76-
'model' => $this->repository->update($user->id, $data),
77-
'exceptions' => $this->revocationService->getExceptions(),
78-
]);
57+
return $response;
7958
}
8059
}

resources/views/admin/users/view.blade.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -102,55 +102,11 @@
102102
</select>
103103
<p class="text-muted"><small>Setting this to 'Yes' gives a user full administrative access.</small></p>
104104
</div>
105-
<div class="checkbox checkbox-primary">
106-
<input type="checkbox" id="pIgnoreConnectionError" value="1" name="ignore_connection_error">
107-
<label for="pIgnoreConnectionError"> Ignore exceptions raised while revoking keys.</label>
108-
<p class="text-muted small">If checked, any errors thrown while revoking keys across nodes will be ignored. You should avoid this checkbox if possible as any non-revoked keys could continue to be active for up to 24 hours after this account is changed. If you are needing to revoke account permissions immediately and are facing node issues, you should check this box and then restart any nodes that failed to be updated to clear out any stored keys.</p>
109-
</div>
110105
</div>
111106
</div>
112107
</div>
113108
</div>
114109
</form>
115-
{{--<div class="col-xs-12">--}}
116-
{{--<div class="box">--}}
117-
{{--<div class="box-header with-border">--}}
118-
{{--<h3 class="box-title">Associated Servers</h3>--}}
119-
{{--</div>--}}
120-
{{--<div class="box-body table-responsive no-padding">--}}
121-
{{--<table class="table table-hover">--}}
122-
{{--<thead>--}}
123-
{{--<tr>--}}
124-
{{--<th style="width:2%;"></th>--}}
125-
{{--<th>Identifier</th>--}}
126-
{{--<th>Server Name</th>--}}
127-
{{--<th>Access</th>--}}
128-
{{--<th>Node</th>--}}
129-
{{--<th style="width:10%;"></th>--}}
130-
{{--</tr>--}}
131-
{{--</thead>--}}
132-
{{--<tbody>--}}
133-
{{--@foreach($user->setAccessLevel('subuser')->access()->get() as $server)--}}
134-
{{--<tr>--}}
135-
{{--<td><a href="{{ route('server.index', $server->uuidShort) }}/"><i class="fa fa-tachometer"></i></a></td>--}}
136-
{{--<td><code>{{ $server->uuidShort }}</code></td>--}}
137-
{{--<td><a href="{{ route('admin.servers.view', $server->id) }}">{{ $server->name }}</a></td>--}}
138-
{{--<td>--}}
139-
{{--@if($server->owner_id === $user->id)--}}
140-
{{--<span class="label bg-purple">Owner</span>--}}
141-
{{--@else--}}
142-
{{--<span class="label bg-blue">Subuser</span>--}}
143-
{{--@endif--}}
144-
{{--</td>--}}
145-
{{--<td><a href="{{ route('admin.nodes.view', $server->node->id) }}">{{ $server->node->name }}</a></td>--}}
146-
{{--<td class="centered">@if($server->suspended === 0)<span class="label muted muted-hover label-success">Active</span>@else<span class="label label-warning">Suspended</span>@endif</td>--}}
147-
{{--</td>--}}
148-
{{--@endforeach--}}
149-
{{--</tbody>--}}
150-
{{--</table>--}}
151-
{{--</div>--}}
152-
{{--</div>--}}
153-
{{--</div>--}}
154110
<div class="col-xs-12">
155111
<div class="box box-danger">
156112
<div class="box-header with-border">

0 commit comments

Comments
 (0)