Files
pterodactyl-panel/app/Http/Requests/Api/Application/Users/StoreUserRequest.php
T

87 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2018-01-19 19:58:57 -06:00
namespace Pterodactyl\Http\Requests\Api\Application\Users;
use Illuminate\Database\Eloquent\Model;
2026-10-11 06:31:11 -04:00
use Pterodactyl\Actions\Users\CreateUser;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
use Pterodactyl\Http\Requests\Concerns\ValidatesExtensionFields;
use Pterodactyl\Models\User;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Support\ValidationRuleSubset;
class StoreUserRequest extends ApplicationApiRequest
{
2026-10-11 06:31:11 -04:00
use ValidatesExtensionFields {
actionInput as private inputWithExtensions;
}
2022-10-14 10:59:20 -06:00
protected ?string $resource = AdminAcl::RESOURCE_USERS;
2022-10-14 10:59:20 -06:00
protected int $permission = AdminAcl::WRITE;
/**
* Return the validation rules for this request.
2026-10-05 18:10:18 -04:00
*
* @param NormalizedValidationRules|null $rules
* @return ValidationRules
*/
2024-10-21 19:18:20 -06:00
public function rules(?array $rules = null): array
{
2026-10-11 06:31:11 -04:00
$rules ??= CreateUser::rules();
2018-02-04 15:38:38 -06:00
2026-10-05 18:10:18 -04:00
$response = ValidationRuleSubset::select($rules, [
'external_id',
'email',
'username',
'password',
'language',
'root_admin',
2026-10-05 18:10:18 -04:00
]);
2018-02-04 15:38:38 -06:00
$response['first_name'] = $rules['name_first'];
$response['last_name'] = $rules['name_last'];
return $response;
}
2026-10-05 18:10:18 -04:00
/**
2026-10-11 06:31:11 -04:00
* The validated input under the action's field names: first_name and last_name are
* its name_first and name_last.
*
* @return ActionInput
2026-10-05 18:10:18 -04:00
*/
2026-10-11 06:31:11 -04:00
public function actionInput(): array
2018-02-04 15:38:38 -06:00
{
2026-10-11 06:31:11 -04:00
$input = $this->inputWithExtensions();
$input['name_first'] = $input['first_name'] ?? null;
$input['name_last'] = $input['last_name'] ?? null;
unset($input['first_name'], $input['last_name']);
2026-10-11 06:31:11 -04:00
return $input;
}
/**
* Rename some fields to be more user friendly.
*/
2022-10-14 10:59:20 -06:00
public function attributes(): array
{
return [
'external_id' => 'Third Party Identifier',
'name_first' => 'First Name',
'name_last' => 'Last Name',
'root_admin' => 'Root Administrator Status',
];
}
/**
* {@inheritdoc}
*/
protected function extensionFieldsModel(): Model|string
{
return User::class;
}
}