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-09 06:26:45 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-10-11 06:31:11 -04:00
|
|
|
use Pterodactyl\Actions\Users\CreateUser;
|
2018-01-19 21:47:06 -06:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
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
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
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
|
|
|
{
|
2026-10-11 06:31:11 -04:00
|
|
|
use ValidatesExtensionFields {
|
|
|
|
|
actionInput as private inputWithExtensions;
|
|
|
|
|
}
|
2026-10-09 06:26:45 +01: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
|
|
|
|
2026-10-12 15:27:35 +05:45
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return parent::authorize() && (! $this->boolean('root_admin') || $this->canManageAdministrators());
|
|
|
|
|
}
|
|
|
|
|
|
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-11 06:31:11 -04:00
|
|
|
$rules ??= CreateUser::rules();
|
2018-02-04 15:38:38 -06:00
|
|
|
|
2026-10-11 23:41:04 -04:00
|
|
|
return [
|
|
|
|
|
'external_id' => $rules['external_id'],
|
|
|
|
|
'email' => $rules['email'],
|
|
|
|
|
'username' => $rules['username'],
|
|
|
|
|
'password' => $rules['password'],
|
|
|
|
|
'language' => $rules['language'],
|
|
|
|
|
'root_admin' => $rules['root_admin'],
|
|
|
|
|
'first_name' => $rules['name_first'],
|
|
|
|
|
'last_name' => $rules['name_last'],
|
|
|
|
|
];
|
2018-02-04 15:38:38 -06:00
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*
|
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
|
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-09 06:26:45 +01:00
|
|
|
|
2026-10-11 06:31:11 -04:00
|
|
|
return $input;
|
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',
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-10-09 06:26:45 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
protected function extensionFieldsModel(): Model|string
|
|
|
|
|
{
|
|
|
|
|
return User::class;
|
|
|
|
|
}
|
2018-01-12 20:39:15 -06:00
|
|
|
}
|