Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/Api/Client/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Illuminate\Http\JsonResponse;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Services\Users\UserUpdateService;
use Pterodactyl\Transformers\Api\Client\AccountTransformer;
use Pterodactyl\Http\Requests\Api\Client\Account\UpdateEmailRequest;
use Pterodactyl\Http\Requests\Api\Client\Account\UpdatePasswordRequest;
use Pterodactyl\Transformers\Api\Client\UserTransformer;

class AccountController extends ClientApiController
{
Expand All @@ -25,7 +25,7 @@ public function __construct(private AuthManager $manager, private UserUpdateServ
public function index(Request $request): array
{
return $this->fractal->item($request->user())
->transformWith($this->getTransformer(AccountTransformer::class))
->transformWith($this->getTransformer(UserTransformer::class))
->toArray();
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/AbstractLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function sendLoginResponse(User $user, Request $request): JsonResponse
'data' => [
'complete' => true,
'intended' => $this->redirectPath(),
'user' => $user->toVueObject(),
'user' => $user->toReactObject(),
],
]);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ public static function getRules(): array
}

/**
* Return the user model in a format that can be passed over to Vue templates.
* Return the user model in a format that can be passed over to React templates.
*/
public function toVueObject(): array
public function toReactObject(): array
{
return Collection::make($this->toArray())->except(['id', 'external_id'])->toArray();
}
Expand Down
1 change: 1 addition & 0 deletions app/Transformers/Api/Application/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function transform(User $user): array
'language' => $user->language,
'root_admin' => (bool) $user->root_admin,
'2fa' => (bool) $user->use_totp,
'2fa_enabled' => (bool) $user->use_totp,
'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at),
];
Expand Down
32 changes: 0 additions & 32 deletions app/Transformers/Api/Client/AccountTransformer.php

This file was deleted.

11 changes: 10 additions & 1 deletion app/Transformers/Api/Client/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ public function getResourceName(): string
public function transform(User $model): array
{
return [
// used in AccountTransformer. Do we want to keep this?
'id' => $model->id,
'uuid' => $model->uuid,
'username' => $model->username,
'email' => $model->email,
'image' => 'https://gravatar.com/avatar/' . md5(Str::lower($model->email)),
// which do we prefer?
'admin' => (bool) $user->root_admin,
'root_admin' => (bool) $user->root_admin,
'2fa_enabled' => $model->use_totp,
'created_at' => $model->created_at->toAtomString(),
'first_name' => $model->name_first,
'last_name' => $model->name_last,
'language' => $model->language,
'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at),
];
}
}
2 changes: 1 addition & 1 deletion resources/views/templates/wrapper.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@section('user-data')
@if(!is_null(Auth::user()))
<script>
window.PterodactylUser = {!! json_encode(Auth::user()->toVueObject()) !!};
window.PterodactylUser = {!! json_encode(Auth::user()->toReactObject()) !!};
</script>
@endif
@if(!empty($siteConfiguration))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function testGetUsers()
$response->assertJsonStructure([
'object',
'data' => [
['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'first_name', 'last_name', 'language', 'root_admin', '2fa', 'created_at', 'updated_at']],
['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'first_name', 'last_name', 'language', 'root_admin', '2fa', 'created_at', 'updated_at']],
['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'first_name', 'last_name', 'language', 'root_admin', '2fa_enabled', '2fa', 'created_at', 'updated_at']],
['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'first_name', 'last_name', 'language', 'root_admin', '2fa_enabled', '2fa', 'created_at', 'updated_at']],
],
'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages']],
]);
Expand Down Expand Up @@ -56,6 +56,7 @@ public function testGetUsers()
'last_name' => $this->getApiUser()->name_last,
'language' => $this->getApiUser()->language,
'root_admin' => $this->getApiUser()->root_admin,
'2fa_enabled' => (bool) $this->getApiUser()->totp_enabled,
'2fa' => (bool) $this->getApiUser()->totp_enabled,
'created_at' => $this->formatTimestamp($this->getApiUser()->created_at),
'updated_at' => $this->formatTimestamp($this->getApiUser()->updated_at),
Expand All @@ -73,6 +74,7 @@ public function testGetUsers()
'last_name' => $user->name_last,
'language' => $user->language,
'root_admin' => (bool) $user->root_admin,
'2fa_enabled' => (bool) $user->totp_enabled,
'2fa' => (bool) $user->totp_enabled,
'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at),
Expand Down
9 changes: 8 additions & 1 deletion tests/Integration/Api/Client/AccountControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ public function testAccountDetailsAreReturned()
'object' => 'user',
'attributes' => [
'id' => $user->id,
'uuid' => $user->uuid,
// TODO: pick one or keep both
'admin' => false,
'root_admin' => false,
'2fa_enabled' => false,
'username' => $user->username,
'email' => $user->email,
'first_name' => $user->name_first,
'last_name' => $user->name_last,
'language' => $user->language,
'language' => 'en',
'image' => 'https://gravatar.com/avatar/' . md5(Str::lower($user->email)),
'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at),
],
]);
}
Expand Down
Loading