Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Console/Commands/User/MakeUserCommand.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Console\Commands\User;
4
5
use Illuminate\Console\Command;
6
use Pterodactyl\Services\Users\UserCreationService;
7
8
class MakeUserCommand extends Command
9
{
10
protected $description = 'Creates a user on the system via the CLI.';
11
12
protected $signature = 'p:user:make {--email=} {--username=} {--name-first=} {--name-last=} {--password=} {--admin=} {--no-password}';
13
14
/**
15
* MakeUserCommand constructor.
16
*/
17
public function __construct(private UserCreationService $creationService)
18
{
19
parent::__construct();
20
}
21
22
/**
23
* Handle command request to create a new user.
24
*
25
* @throws \Exception
26
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
27
*/
28
public function handle()
29
{
30
$root_admin = $this->option('admin') ?? $this->confirm(trans('command/messages.user.ask_admin'));
31
$email = $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email'));
32
$username = $this->option('username') ?? $this->ask(trans('command/messages.user.ask_username'));
33
$name_first = $this->option('name-first') ?? $this->ask(trans('command/messages.user.ask_name_first'));
34
$name_last = $this->option('name-last') ?? $this->ask(trans('command/messages.user.ask_name_last'));
35
36
if (is_null($password = $this->option('password')) && !$this->option('no-password')) {
37
$this->warn(trans('command/messages.user.ask_password_help'));
38
$this->line(trans('command/messages.user.ask_password_tip'));
39
$password = $this->secret(trans('command/messages.user.ask_password'));
40
}
41
42
$user = $this->creationService->handle(compact('email', 'username', 'name_first', 'name_last', 'password', 'root_admin'));
43
$this->table(['Field', 'Value'], [
44
['UUID', $user->uuid],
45
['Email', $user->email],
46
['Username', $user->username],
47
['Name', $user->name],
48
['Admin', $user->root_admin ? 'Yes' : 'No'],
49
]);
50
}
51
}
52
53