2018-01-12 20:39:15 -06:00
|
|
|
<?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;
|
2018-01-12 20:39:15 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Support\Arr;
|
2018-01-19 21:47:06 -06:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|
|
|
|
use Pterodactyl\Support\JsonValueGuard;
|
|
|
|
|
use Pterodactyl\Support\ValidationRuleSubset;
|
|
|
|
|
use Pterodactyl\Validation\UserRules;
|
2018-01-12 20:39:15 -06:00
|
|
|
|
2018-01-19 21:47:06 -06:00
|
|
|
class StoreUserRequest extends ApplicationApiRequest
|
2018-01-12 20:39:15 -06:00
|
|
|
{
|
2022-10-14 10:59:20 -06:00
|
|
|
protected ?string $resource = AdminAcl::RESOURCE_USERS;
|
2018-01-12 20:39:15 -06:00
|
|
|
|
2022-10-14 10:59:20 -06:00
|
|
|
protected int $permission = AdminAcl::WRITE;
|
2018-01-12 20:39:15 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the validation rules for this request.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @param NormalizedValidationRules|null $rules
|
|
|
|
|
* @return ValidationRules
|
2018-01-12 20:39:15 -06:00
|
|
|
*/
|
2024-10-21 19:18:20 -06:00
|
|
|
public function rules(?array $rules = null): array
|
2018-01-12 20:39:15 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$rules ??= UserRules::rules();
|
2018-02-04 15:38:38 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
$response = ValidationRuleSubset::select($rules, [
|
2018-01-12 20:39:15 -06:00
|
|
|
'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
|
|
|
/**
|
|
|
|
|
* @return UserCreationData
|
|
|
|
|
*/
|
|
|
|
|
public function payload(): array
|
2018-02-04 15:38:38 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$validated = parent::validated();
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'email' => JsonValueGuard::string(Arr::get($validated, 'email')),
|
|
|
|
|
'username' => JsonValueGuard::string(Arr::get($validated, 'username')),
|
|
|
|
|
'name_first' => JsonValueGuard::string(Arr::get($validated, 'first_name')),
|
|
|
|
|
'name_last' => JsonValueGuard::string(Arr::get($validated, 'last_name')),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach (['external_id', 'password'] as $nullable) {
|
|
|
|
|
if (array_key_exists($nullable, $validated)) {
|
|
|
|
|
$value = Arr::get($validated, $nullable);
|
|
|
|
|
$data[$nullable] = $value !== null && $value !== '' ? JsonValueGuard::string($value) : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-04 15:38:38 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
if (array_key_exists('root_admin', $validated)) {
|
|
|
|
|
$data['root_admin'] = JsonValueGuard::boolean(Arr::get($validated, 'root_admin'));
|
|
|
|
|
}
|
2018-02-04 15:38:38 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
$language = Arr::get($validated, 'language');
|
|
|
|
|
if ($language !== null && $language !== '') {
|
|
|
|
|
$data['language'] = JsonValueGuard::string($language);
|
|
|
|
|
}
|
2018-02-04 15:38:38 -06:00
|
|
|
|
|
|
|
|
return $data;
|
2018-01-12 20:39:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rename some fields to be more user friendly.
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function attributes(): array
|
2018-01-12 20:39:15 -06:00
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'external_id' => 'Third Party Identifier',
|
|
|
|
|
'name_first' => 'First Name',
|
|
|
|
|
'name_last' => 'Last Name',
|
|
|
|
|
'root_admin' => 'Root Administrator Status',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|