mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 22:14:45 +02:00

* Init * Health Page * Admin API Keys * Update API Keys * Database Hosts * Mounts * remove `s` * Users * Webhooks * Server never again... * Fix Server * Settings * Update Mounts * Update Databasehost * Update Server * Oops, Update Server * Nodes * Update User * Dashboard * Update Server * Profile * Egg * Role & Update Egg * Add base Laravel lang files * update apikey * remove html back to settings, remove comment * add `:resource` to create_action * Update Egg * Update Egg v2 * Update 1 * trans cf info label * Update charts * more trans * Update Webhook * update Health * Update Server * Update Role * Fixes * Bulk Update * AnotherOne * Fix relation button label * rename `admin1` to `admin` Leftover from testing... oops * More Translations * Updates * `pint` + Relation Manager Titles
87 lines
2.5 KiB
PHP
87 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Admin\Resources\UserResource\Pages;
|
|
|
|
use App\Filament\Admin\Resources\UserResource;
|
|
use App\Models\Role;
|
|
use App\Services\Users\UserCreationService;
|
|
use Filament\Forms\Components\CheckboxList;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CreateUser extends CreateRecord
|
|
{
|
|
protected static string $resource = UserResource::class;
|
|
|
|
protected static bool $canCreateAnother = false;
|
|
|
|
private UserCreationService $service;
|
|
|
|
public function boot(UserCreationService $service): void
|
|
{
|
|
$this->service = $service;
|
|
}
|
|
|
|
public function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->columns(['default' => 1, 'lg' => 3])
|
|
->schema([
|
|
TextInput::make('username')
|
|
->label(trans('admin/user.username'))
|
|
->alphaNum()
|
|
->required()
|
|
->unique()
|
|
->minLength(3)
|
|
->maxLength(255),
|
|
TextInput::make('email')
|
|
->label(trans('admin/user.email'))
|
|
->email()
|
|
->required()
|
|
->unique()
|
|
->maxLength(255),
|
|
TextInput::make('password')
|
|
->label(trans('admin/user.password'))
|
|
->hintIcon('tabler-question-mark')
|
|
->hintIconTooltip(trans('admin/user.password_help'))
|
|
->password(),
|
|
CheckboxList::make('roles')
|
|
->disableOptionWhen(fn (string $value): bool => $value == Role::getRootAdmin()->id)
|
|
->relationship('roles', 'name')
|
|
->dehydrated()
|
|
->label(trans('admin/user.admin_roles'))
|
|
->columnSpanFull()
|
|
->bulkToggleable(false),
|
|
]);
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
$this->getCreateFormAction()->formId('form'),
|
|
];
|
|
}
|
|
|
|
protected function getFormActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
protected function handleRecordCreation(array $data): Model
|
|
{
|
|
$data['root_admin'] = false;
|
|
|
|
$roles = $data['roles'];
|
|
$roles = collect($roles)->map(fn ($role) => Role::findById($role));
|
|
unset($data['roles']);
|
|
|
|
$user = $this->service->handle($data);
|
|
|
|
$user->syncRoles($roles);
|
|
|
|
return $user;
|
|
}
|
|
}
|