2026-10-05 18:10:18 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Api\Admin\Users;
|
|
|
|
|
|
2026-10-09 06:26:45 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-10-11 06:31:11 -04:00
|
|
|
use Pterodactyl\Actions\Users\CreateUser;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Enum\Permissions;
|
|
|
|
|
use Pterodactyl\Http\Requests\Api\Admin\AdminApiRequest;
|
2026-10-09 06:26:45 +01:00
|
|
|
use Pterodactyl\Http\Requests\Concerns\ValidatesExtensionFields;
|
|
|
|
|
use Pterodactyl\Models\User;
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
class StoreUserRequest extends AdminApiRequest
|
|
|
|
|
{
|
2026-10-11 06:31:11 -04:00
|
|
|
use ValidatesExtensionFields {
|
|
|
|
|
actionInput as private inputWithExtensions;
|
|
|
|
|
}
|
2026-10-09 06:26:45 +01:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public function permissions(): array
|
|
|
|
|
{
|
|
|
|
|
return [Permissions::AdminUsersCreate];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validation rules for creating a user.
|
|
|
|
|
*
|
|
|
|
|
* @param NormalizedValidationRules|null $rules
|
|
|
|
|
* @return ValidationRules
|
|
|
|
|
*/
|
|
|
|
|
public function rules(?array $rules = null): array
|
|
|
|
|
{
|
2026-10-11 06:31:11 -04:00
|
|
|
$rules ??= CreateUser::rules();
|
2026-10-05 18:10:18 -04:00
|
|
|
|
2026-10-11 23:41:04 -04:00
|
|
|
return [
|
|
|
|
|
'external_id' => $rules['external_id'],
|
|
|
|
|
'email' => $rules['email'],
|
|
|
|
|
'username' => $rules['username'],
|
|
|
|
|
'password' => $rules['password'],
|
|
|
|
|
'root_admin' => $rules['root_admin'],
|
|
|
|
|
'name_first' => $rules['name_first'],
|
|
|
|
|
'name_last' => $rules['name_last'],
|
|
|
|
|
// Nested on input; actionInput() hands it to the action as `language`.
|
|
|
|
|
'preferences.language' => $rules['language'],
|
|
|
|
|
];
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-11 06:31:11 -04:00
|
|
|
* The validated input, with the language sent under `preferences` moved to the
|
|
|
|
|
* action's `language` key.
|
|
|
|
|
*
|
2026-10-11 19:54:55 -04:00
|
|
|
* @return array<string, mixed>
|
2026-10-05 18:10:18 -04:00
|
|
|
*/
|
2026-10-11 06:31:11 -04:00
|
|
|
public function actionInput(): array
|
2026-10-05 18:10:18 -04:00
|
|
|
{
|
2026-10-11 06:31:11 -04:00
|
|
|
$input = $this->inputWithExtensions();
|
|
|
|
|
unset($input['preferences']);
|
2026-10-05 18:10:18 -04:00
|
|
|
|
2026-10-11 06:31:11 -04:00
|
|
|
$validated = $this->safe();
|
|
|
|
|
if ($validated->has('preferences.language')) {
|
|
|
|
|
$input['language'] = $validated->string('preferences.language')->toString();
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
2026-10-11 06:31:11 -04:00
|
|
|
return $input;
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Rename fields to be more clear in error messages. */
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'external_id' => 'Third Party Identifier',
|
|
|
|
|
'name_first' => 'First Name',
|
|
|
|
|
'name_last' => 'Last Name',
|
|
|
|
|
'root_admin' => 'Root Administrator Status',
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-10-09 06:26:45 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
protected function extensionFieldsModel(): Model|string
|
|
|
|
|
{
|
|
|
|
|
return User::class;
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|