2017-09-16 03:13:33 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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-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.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Services\Users\UserCreationService $creationService
|
|
|
|
*/
|
|
|
|
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'));
|
|
|
|
$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'));
|
|
|
|
|
|
|
|
if (is_null($password = $this->option('password')) && ! $this->option('no-password')) {
|
|
|
|
$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'));
|
|
|
|
}
|
|
|
|
|
2017-09-16 04:46:22 +00:00
|
|
|
$user = $this->creationService->handle(compact('email', 'username', 'name_first', 'name_last', 'password', 'root_admin'));
|
2017-09-16 03:13:33 +00:00
|
|
|
$this->table(['Field', 'Value'], [
|
|
|
|
['UUID', $user->uuid],
|
|
|
|
['Email', $user->email],
|
|
|
|
['Username', $user->username],
|
|
|
|
['Name', $user->name],
|
2017-09-16 04:46:22 +00:00
|
|
|
['Admin', $user->root_admin ? 'Yes' : 'No'],
|
2017-09-16 03:13:33 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|