mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 14:34:44 +02:00
Add ability to create User on Create Server page (#442)
* Add ability to create a User on Create Server page * pint * Fix creating user without password --------- Co-authored-by: notCharles <charles@pelican.dev>
This commit is contained in:
parent
2a740b43e6
commit
75d35e6ee8
@ -6,9 +6,11 @@ use App\Filament\Resources\ServerResource;
|
|||||||
use App\Models\Allocation;
|
use App\Models\Allocation;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
use App\Models\Node;
|
use App\Models\Node;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\Allocations\AssignmentService;
|
use App\Services\Allocations\AssignmentService;
|
||||||
use App\Services\Servers\RandomWordService;
|
use App\Services\Servers\RandomWordService;
|
||||||
use App\Services\Servers\ServerCreationService;
|
use App\Services\Servers\ServerCreationService;
|
||||||
|
use App\Services\Users\UserCreationService;
|
||||||
use Filament\Forms\Components\Actions\Action;
|
use Filament\Forms\Components\Actions\Action;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
@ -67,6 +69,7 @@ class CreateServer extends CreateRecord
|
|||||||
->maxLength(255),
|
->maxLength(255),
|
||||||
|
|
||||||
Forms\Components\Select::make('owner_id')
|
Forms\Components\Select::make('owner_id')
|
||||||
|
->preload()
|
||||||
->prefixIcon('tabler-user')
|
->prefixIcon('tabler-user')
|
||||||
->default(auth()->user()->id)
|
->default(auth()->user()->id)
|
||||||
->label('Owner')
|
->label('Owner')
|
||||||
@ -77,8 +80,44 @@ class CreateServer extends CreateRecord
|
|||||||
'lg' => 3,
|
'lg' => 3,
|
||||||
])
|
])
|
||||||
->relationship('user', 'username')
|
->relationship('user', 'username')
|
||||||
->searchable()
|
->searchable(['user', 'username', 'email'])
|
||||||
->preload()
|
->getOptionLabelFromRecordUsing(fn (User $user) => "$user->email | $user->username " . ($user->root_admin ? '(admin)' : ''))
|
||||||
|
->createOptionForm([
|
||||||
|
Forms\Components\TextInput::make('username')
|
||||||
|
->alphaNum()
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
|
||||||
|
Forms\Components\TextInput::make('email')
|
||||||
|
->email()
|
||||||
|
->required()
|
||||||
|
->unique()
|
||||||
|
->maxLength(255),
|
||||||
|
|
||||||
|
Forms\Components\TextInput::make('password')
|
||||||
|
->hintIcon('tabler-question-mark')
|
||||||
|
->hintIconTooltip('Providing a user password is optional. New user email will prompt users to create a password the first time they login.')
|
||||||
|
->password(),
|
||||||
|
|
||||||
|
Forms\Components\ToggleButtons::make('root_admin')
|
||||||
|
->label('Administrator (Root)')
|
||||||
|
->options([
|
||||||
|
false => 'No',
|
||||||
|
true => 'Admin',
|
||||||
|
])
|
||||||
|
->colors([
|
||||||
|
false => 'primary',
|
||||||
|
true => 'danger',
|
||||||
|
])
|
||||||
|
->inline()
|
||||||
|
->required()
|
||||||
|
->default(false)
|
||||||
|
->hidden(),
|
||||||
|
])
|
||||||
|
->createOptionUsing(function ($data) {
|
||||||
|
resolve(UserCreationService::class)->handle($data);
|
||||||
|
$this->refreshForm();
|
||||||
|
})
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
Forms\Components\Select::make('node_id')
|
Forms\Components\Select::make('node_id')
|
||||||
@ -751,6 +790,11 @@ class CreateServer extends CreateRecord
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function refreshForm(): void
|
||||||
|
{
|
||||||
|
$this->fillForm();
|
||||||
|
}
|
||||||
|
|
||||||
protected function getFormActions(): array
|
protected function getFormActions(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user