2023-03-14 16:17:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\AppUser;
|
|
|
|
|
|
2023-03-15 10:41:01 +01:00
|
|
|
use App\Enums\AppUserRolesEnum;
|
2025-05-26 11:33:47 +02:00
|
|
|
use App\Models\AppUser;
|
2023-03-14 16:17:23 +01:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2025-05-26 11:33:47 +02:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
use Illuminate\Support\Str;
|
2025-05-20 16:20:23 +02:00
|
|
|
use Illuminate\Validation\Rule;
|
2025-05-20 10:16:12 +02:00
|
|
|
use Illuminate\Validation\Rules\Enum;
|
2023-07-25 12:55:22 +02:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
2023-03-14 16:17:23 +01:00
|
|
|
|
|
|
|
|
class StoreAppUserRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
2023-03-15 10:41:01 +01:00
|
|
|
* @return boolean
|
2023-03-14 16:17:23 +01:00
|
|
|
*/
|
2025-05-20 10:16:12 +02:00
|
|
|
public function authorize(): bool
|
2023-03-14 16:17:23 +01:00
|
|
|
{
|
2025-05-26 11:33:47 +02:00
|
|
|
return Gate::check('create', AppUser::class);
|
2023-03-14 16:17:23 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-31 15:24:32 +02:00
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2025-05-20 10:16:12 +02:00
|
|
|
protected function prepareForValidation(): void
|
2023-03-31 15:24:32 +02:00
|
|
|
{
|
|
|
|
|
$this->merge([
|
2025-05-20 10:16:12 +02:00
|
|
|
'status' => $this->status ? true : false,
|
2023-03-31 15:24:32 +02:00
|
|
|
'authorizedFolders' => $this->authorizedFolders ? $this->authorizedFolders : [],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 16:17:23 +01:00
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2025-05-20 10:16:12 +02:00
|
|
|
public function rules(): array
|
2023-03-14 16:17:23 +01:00
|
|
|
{
|
|
|
|
|
return [
|
2025-05-20 10:16:12 +02:00
|
|
|
'lastname' => 'required|min:3|max:255',
|
|
|
|
|
'firstname' => 'required|min:3|max:255',
|
2025-05-20 16:20:23 +02:00
|
|
|
'email' => [
|
|
|
|
|
'required',
|
|
|
|
|
'email:rfc,strict,dns,spoof,filter',
|
|
|
|
|
Rule::unique('app_users', 'email')->where('tenant_id', tenant('id'))
|
|
|
|
|
],
|
2025-05-20 10:16:12 +02:00
|
|
|
'password' => [
|
|
|
|
|
'required',
|
|
|
|
|
'required_with:password_confirmation',
|
|
|
|
|
'confirmed',
|
|
|
|
|
'max:255',
|
2023-07-25 12:55:22 +02:00
|
|
|
Password::min(8)
|
|
|
|
|
->letters()
|
|
|
|
|
->mixedCase()
|
|
|
|
|
->numbers()
|
|
|
|
|
->symbols()
|
|
|
|
|
],
|
2023-03-31 15:24:32 +02:00
|
|
|
'authorizedFolders' => 'present|array',
|
2025-05-20 10:16:12 +02:00
|
|
|
'role' => [
|
2023-03-15 10:41:01 +01:00
|
|
|
'required',
|
2025-05-20 10:16:12 +02:00
|
|
|
new Enum(AppUserRolesEnum::class)
|
2023-03-15 10:41:01 +01:00
|
|
|
],
|
2025-05-20 10:16:12 +02:00
|
|
|
'status' => 'required|boolean'
|
2023-03-15 10:41:01 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2025-05-20 10:16:12 +02:00
|
|
|
public function attributes(): array
|
2023-03-15 10:41:01 +01:00
|
|
|
{
|
|
|
|
|
return [
|
2025-05-26 11:33:47 +02:00
|
|
|
'lastname' => \trans('validation.attributes.last_name'),
|
|
|
|
|
'firstname' => \trans('validation.attributes.first_name'),
|
|
|
|
|
'email' => \trans('validation.attributes.email'),
|
|
|
|
|
'password' => \trans('validation.attributes.password'),
|
|
|
|
|
'authorizedFolders' => Str::of(\trans('models.classes.directory'))->plural(),
|
|
|
|
|
'role' => \trans('validation.custom.role'),
|
|
|
|
|
'status' => \trans('validation.custom.status')
|
2023-03-14 16:17:23 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|