Path: blob/1.0-develop/app/Console/Commands/User/MakeUserCommand.php
7461 views
<?php12namespace Pterodactyl\Console\Commands\User;34use Illuminate\Console\Command;5use Pterodactyl\Services\Users\UserCreationService;67class MakeUserCommand extends Command8{9protected $description = 'Creates a user on the system via the CLI.';1011protected $signature = 'p:user:make {--email=} {--username=} {--name-first=} {--name-last=} {--password=} {--admin=} {--no-password}';1213/**14* MakeUserCommand constructor.15*/16public function __construct(private UserCreationService $creationService)17{18parent::__construct();19}2021/**22* Handle command request to create a new user.23*24* @throws \Exception25* @throws \Pterodactyl\Exceptions\Model\DataValidationException26*/27public function handle()28{29$root_admin = $this->option('admin') ?? $this->confirm(trans('command/messages.user.ask_admin'));30$email = $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email'));31$username = $this->option('username') ?? $this->ask(trans('command/messages.user.ask_username'));32$name_first = $this->option('name-first') ?? $this->ask(trans('command/messages.user.ask_name_first'));33$name_last = $this->option('name-last') ?? $this->ask(trans('command/messages.user.ask_name_last'));3435if (is_null($password = $this->option('password')) && !$this->option('no-password')) {36$this->warn(trans('command/messages.user.ask_password_help'));37$this->line(trans('command/messages.user.ask_password_tip'));38$password = $this->secret(trans('command/messages.user.ask_password'));39}4041$user = $this->creationService->handle(compact('email', 'username', 'name_first', 'name_last', 'password', 'root_admin'));42$this->table(['Field', 'Value'], [43['UUID', $user->uuid],44['Email', $user->email],45['Username', $user->username],46['Name', $user->name],47['Admin', $user->root_admin ? 'Yes' : 'No'],48]);49}50}515253