2017-09-15 22:13:33 -05:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-09-15 22:13:33 -05:00
|
|
|
namespace Pterodactyl\Console\Commands\User;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Console\Attributes\Description;
|
|
|
|
|
use Illuminate\Console\Attributes\Signature;
|
2017-09-15 22:13:33 -05:00
|
|
|
use Illuminate\Console\Command;
|
2026-10-11 06:31:11 -04:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Contracts\Users\CreatesUsers;
|
|
|
|
|
use Throwable;
|
2017-09-15 22:13:33 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Description('Creates a user on the system via the CLI.')]
|
|
|
|
|
#[Signature('p:user:make {--email=} {--username=} {--name-first=} {--name-last=} {--password=} {--admin=} {--no-password}')]
|
2017-09-15 22:13:33 -05:00
|
|
|
class MakeUserCommand extends Command
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Handle command request to create a new user.
|
|
|
|
|
*
|
2026-10-05 18:10:18 -04:00
|
|
|
* @throws Throwable
|
2017-09-15 22:13:33 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function handle(CreatesUsers $users): int
|
2017-09-15 22:13:33 -05:00
|
|
|
{
|
2026-10-11 20:11:13 -04:00
|
|
|
$input = [
|
|
|
|
|
'root_admin' => $this->option('admin') ?? $this->confirm(trans('command/messages.user.ask_admin')),
|
2026-10-11 16:30:09 -04:00
|
|
|
'email' => $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email')),
|
|
|
|
|
'username' => $this->option('username') ?? $this->ask(trans('command/messages.user.ask_username')),
|
|
|
|
|
'name_first' => $this->option('name-first') ?? $this->ask(trans('command/messages.user.ask_name_first')),
|
|
|
|
|
'name_last' => $this->option('name-last') ?? $this->ask(trans('command/messages.user.ask_name_last')),
|
|
|
|
|
'password' => $this->option('password'),
|
2026-10-11 20:11:13 -04:00
|
|
|
];
|
2017-09-15 22:13:33 -05:00
|
|
|
|
2026-10-11 20:11:13 -04:00
|
|
|
if ($input['password'] === null && ! $this->option('no-password')) {
|
2017-09-15 22:13:33 -05:00
|
|
|
$this->warn(trans('command/messages.user.ask_password_help'));
|
|
|
|
|
$this->line(trans('command/messages.user.ask_password_tip'));
|
2026-10-11 20:11:13 -04:00
|
|
|
$input['password'] = $this->secret(trans('command/messages.user.ask_password'));
|
2017-09-15 22:13:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-10-11 06:31:11 -04:00
|
|
|
try {
|
2026-10-11 20:11:13 -04:00
|
|
|
$user = $users->create($input);
|
2026-10-11 06:31:11 -04:00
|
|
|
} catch (ValidationException $validationException) {
|
|
|
|
|
foreach ($validationException->validator->errors()->all() as $error) {
|
2026-10-05 18:10:18 -04:00
|
|
|
$this->error($error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:13:33 -05:00
|
|
|
$this->table(['Field', 'Value'], [
|
|
|
|
|
['UUID', $user->uuid],
|
|
|
|
|
['Email', $user->email],
|
|
|
|
|
['Username', $user->username],
|
|
|
|
|
['Name', $user->name],
|
2017-09-15 23:46:22 -05:00
|
|
|
['Admin', $user->root_admin ? 'Yes' : 'No'],
|
2017-09-15 22:13:33 -05:00
|
|
|
]);
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
return 0;
|
2017-09-15 22:13:33 -05:00
|
|
|
}
|
|
|
|
|
}
|