diff --git a/app/Http/Controllers/Api/Client/AccountController.php b/app/Http/Controllers/Api/Client/AccountController.php index 5dedef7141..e88114e56d 100644 --- a/app/Http/Controllers/Api/Client/AccountController.php +++ b/app/Http/Controllers/Api/Client/AccountController.php @@ -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 { @@ -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(); } diff --git a/app/Http/Controllers/Auth/AbstractLoginController.php b/app/Http/Controllers/Auth/AbstractLoginController.php index 11d3744c01..09e51abb84 100644 --- a/app/Http/Controllers/Auth/AbstractLoginController.php +++ b/app/Http/Controllers/Auth/AbstractLoginController.php @@ -85,7 +85,7 @@ protected function sendLoginResponse(User $user, Request $request): JsonResponse 'data' => [ 'complete' => true, 'intended' => $this->redirectPath(), - 'user' => $user->toVueObject(), + 'user' => $user->toReactObject(), ], ]); } diff --git a/app/Models/User.php b/app/Models/User.php index 02df0ca093..cf686a802c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -194,9 +194,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']) ->merge(['identifier' => $this->identifier]) diff --git a/app/Transformers/Api/Application/UserTransformer.php b/app/Transformers/Api/Application/UserTransformer.php index 14e354b45d..39a038299a 100644 --- a/app/Transformers/Api/Application/UserTransformer.php +++ b/app/Transformers/Api/Application/UserTransformer.php @@ -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), ]; diff --git a/app/Transformers/Api/Client/AccountTransformer.php b/app/Transformers/Api/Client/AccountTransformer.php deleted file mode 100644 index 1a14555d83..0000000000 --- a/app/Transformers/Api/Client/AccountTransformer.php +++ /dev/null @@ -1,32 +0,0 @@ - $model->id, - 'admin' => $model->root_admin, - 'username' => $model->username, - 'email' => $model->email, - 'first_name' => $model->name_first, - 'last_name' => $model->name_last, - 'language' => $model->language, - ]; - } -} diff --git a/app/Transformers/Api/Client/UserTransformer.php b/app/Transformers/Api/Client/UserTransformer.php index 559aa190d5..8a01934661 100644 --- a/app/Transformers/Api/Client/UserTransformer.php +++ b/app/Transformers/Api/Client/UserTransformer.php @@ -22,13 +22,22 @@ 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, 'identifier' => $model->identifier, 'username' => $model->username, 'email' => $model->email, 'image' => 'https://gravatar.com/avatar/' . md5(Str::lower($model->email)), - '2fa_enabled' => $model->use_totp, - 'created_at' => $model->created_at->toAtomString(), + // which do we prefer? + 'admin' => (bool) $model->root_admin, + 'root_admin' => (bool) $model->root_admin, + '2fa_enabled' => (bool) $model->use_totp, + 'first_name' => $model->name_first, + 'last_name' => $model->name_last, + 'language' => $model->language, + 'created_at' => $this->formatTimestamp($model->created_at), + 'updated_at' => $this->formatTimestamp($model->updated_at), ]; } } diff --git a/resources/views/templates/wrapper.blade.php b/resources/views/templates/wrapper.blade.php index a2d218a537..015d845ced 100644 --- a/resources/views/templates/wrapper.blade.php +++ b/resources/views/templates/wrapper.blade.php @@ -22,7 +22,7 @@ @section('user-data') @if(!is_null(Auth::user())) @endif @if(!empty($siteConfiguration)) diff --git a/tests/Integration/Api/Application/Users/UserControllerTest.php b/tests/Integration/Api/Application/Users/UserControllerTest.php index a2512094b4..95b3fd6fd6 100644 --- a/tests/Integration/Api/Application/Users/UserControllerTest.php +++ b/tests/Integration/Api/Application/Users/UserControllerTest.php @@ -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']], ]); @@ -56,7 +56,8 @@ public function testGetUsers() 'last_name' => $this->getApiUser()->name_last, 'language' => $this->getApiUser()->language, 'root_admin' => $this->getApiUser()->root_admin, - '2fa' => (bool) $this->getApiUser()->totp_enabled, + '2fa_enabled' => (bool) $this->getApiUser()->use_totp, + '2fa' => (bool) $this->getApiUser()->use_totp, 'created_at' => $this->formatTimestamp($this->getApiUser()->created_at), 'updated_at' => $this->formatTimestamp($this->getApiUser()->updated_at), ], @@ -73,7 +74,8 @@ public function testGetUsers() 'last_name' => $user->name_last, 'language' => $user->language, 'root_admin' => (bool) $user->root_admin, - '2fa' => (bool) $user->totp_enabled, + '2fa_enabled' => (bool) $user->use_totp, + '2fa' => (bool) $user->use_totp, 'created_at' => $this->formatTimestamp($user->created_at), 'updated_at' => $this->formatTimestamp($user->updated_at), ], diff --git a/tests/Integration/Api/Client/AccountControllerTest.php b/tests/Integration/Api/Client/AccountControllerTest.php index 27d50f28c9..82c4ad6251 100644 --- a/tests/Integration/Api/Client/AccountControllerTest.php +++ b/tests/Integration/Api/Client/AccountControllerTest.php @@ -26,12 +26,20 @@ public function testAccountDetailsAreReturned() 'object' => 'user', 'attributes' => [ 'id' => $user->id, + 'uuid' => $user->uuid, + 'identifier' => $user->identifier, + // 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), ], ]); }