Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Api/Application/Users/StoreUserRequest.php
10283 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Api\Application\Users;
4
5
use Pterodactyl\Models\User;
6
use Pterodactyl\Services\Acl\Api\AdminAcl;
7
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
8
9
class StoreUserRequest extends ApplicationApiRequest
10
{
11
protected ?string $resource = AdminAcl::RESOURCE_USERS;
12
13
protected int $permission = AdminAcl::WRITE;
14
15
/**
16
* Return the validation rules for this request.
17
*/
18
public function rules(?array $rules = null): array
19
{
20
$rules = $rules ?? User::getRules();
21
22
$response = collect($rules)->only([
23
'external_id',
24
'email',
25
'username',
26
'password',
27
'language',
28
'root_admin',
29
])->toArray();
30
31
$response['first_name'] = $rules['name_first'];
32
$response['last_name'] = $rules['name_last'];
33
34
return $response;
35
}
36
37
public function validated($key = null, $default = null): array
38
{
39
$data = parent::validated();
40
41
$data['name_first'] = $data['first_name'];
42
$data['name_last'] = $data['last_name'];
43
44
unset($data['first_name'], $data['last_name']);
45
46
return $data;
47
}
48
49
/**
50
* Rename some fields to be more user friendly.
51
*/
52
public function attributes(): array
53
{
54
return [
55
'external_id' => 'Third Party Identifier',
56
'name_first' => 'First Name',
57
'name_last' => 'Last Name',
58
'root_admin' => 'Root Administrator Status',
59
];
60
}
61
}
62
63