2017-09-16 03:13:33 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-16 03:13:33 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-16 03:13:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\User;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Pterodactyl\Services\Users\UserCreationService;
|
|
|
|
|
|
|
|
class MakeUserCommand extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Users\UserCreationService
|
|
|
|
*/
|
|
|
|
protected $creationService;
|
|
|
|
|
2017-09-21 05:16:01 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Creates a user on the system via the CLI.';
|
|
|
|
|
2017-09-16 04:46:22 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'p:user:make {--email=} {--username=} {--name-first=} {--name-last=} {--password=} {--admin=} {--no-password}';
|
2017-09-16 03:13:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MakeUserCommand constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(UserCreationService $creationService)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->creationService = $creationService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle command request to create a new user.
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2017-09-16 04:46:22 +00:00
|
|
|
$root_admin = $this->option('admin') ?? $this->confirm(trans('command/messages.user.ask_admin'));
|
2017-09-16 03:13:33 +00: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'));
|
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (is_null($password = $this->option('password')) && !$this->option('no-password')) {
|
2017-09-16 03:13:33 +00:00
|
|
|
$this->warn(trans('command/messages.user.ask_password_help'));
|
|
|
|
$this->line(trans('command/messages.user.ask_password_tip'));
|
|
|
|
$password = $this->secret(trans('command/messages.user.ask_password'));
|
|
|
|
}
|
|
|
|
|
2021-07-29 03:31:00 +00:00
|
|
|
$user = $this->creationService->handle(compact('email', 'username', 'password', 'root_admin'));
|
2017-09-16 03:13:33 +00:00
|
|
|
$this->table(['Field', 'Value'], [
|
|
|
|
['UUID', $user->uuid],
|
|
|
|
['Email', $user->email],
|
|
|
|
['Username', $user->username],
|
2021-10-30 20:41:38 +00:00
|
|
|
['Name', $user->name_first],
|
2017-09-16 04:46:22 +00:00
|
|
|
['Admin', $user->root_admin ? 'Yes' : 'No'],
|
2017-09-16 03:13:33 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|