2018-01-13 02:39:15 +00:00
|
|
|
<?php
|
|
|
|
|
2018-01-20 01:58:57 +00:00
|
|
|
namespace Pterodactyl\Http\Requests\Api\Application\Users;
|
2018-01-13 02:39:15 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
2018-01-20 03:47:06 +00:00
|
|
|
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
2018-01-13 02:39:15 +00:00
|
|
|
|
2018-01-20 03:47:06 +00:00
|
|
|
class StoreUserRequest extends ApplicationApiRequest
|
2018-01-13 02:39:15 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $resource = AdminAcl::RESOURCE_USERS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $permission = AdminAcl::WRITE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the validation rules for this request.
|
|
|
|
*
|
2018-02-04 21:38:38 +00:00
|
|
|
* @param array|null $rules
|
2018-01-13 02:39:15 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2018-02-04 21:38:38 +00:00
|
|
|
public function rules(array $rules = null): array
|
2018-01-13 02:39:15 +00:00
|
|
|
{
|
2019-09-05 05:26:28 +00:00
|
|
|
$rules = $rules ?? User::getRules();
|
2018-02-04 21:38:38 +00:00
|
|
|
|
|
|
|
$response = collect($rules)->only([
|
2018-01-13 02:39:15 +00:00
|
|
|
'external_id',
|
|
|
|
'email',
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'language',
|
|
|
|
'root_admin',
|
|
|
|
])->toArray();
|
2018-02-04 21:38:38 +00:00
|
|
|
|
|
|
|
$response['first_name'] = $rules['name_first'];
|
|
|
|
$response['last_name'] = $rules['name_last'];
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function validated()
|
|
|
|
{
|
|
|
|
$data = parent::validated();
|
|
|
|
|
|
|
|
$data['name_first'] = $data['first_name'];
|
|
|
|
$data['name_last'] = $data['last_name'];
|
|
|
|
|
|
|
|
unset($data['first_name'], $data['last_name']);
|
|
|
|
|
|
|
|
return $data;
|
2018-01-13 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename some fields to be more user friendly.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function attributes()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'external_id' => 'Third Party Identifier',
|
|
|
|
'name_first' => 'First Name',
|
|
|
|
'name_last' => 'Last Name',
|
|
|
|
'root_admin' => 'Root Administrator Status',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|