1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Pterodactyl - Panel |
4
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in all |
14
|
|
|
* copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Pterodactyl\Console\Commands; |
26
|
|
|
|
27
|
|
|
use Illuminate\Console\Command; |
28
|
|
|
use Pterodactyl\Repositories\UserRepository; |
29
|
|
|
|
30
|
|
|
class MakeUser extends Command |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* The name and signature of the console command. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $signature = 'pterodactyl:user |
38
|
|
|
{--firstname= : First name to use for this account.} |
39
|
|
|
{--lastname= : Last name to use for this account.} |
40
|
|
|
{--username= : Username to use for this account.} |
41
|
|
|
{--email= : Email address to use for this account.} |
42
|
|
|
{--password= : Password to assign to the user.} |
43
|
|
|
{--admin= : Boolean flag for if user should be an admin.}'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The console command description. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $description = 'Create a user within the panel.'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Create a new command instance. |
54
|
|
|
* |
55
|
|
|
* @return void |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
public function __construct() |
58
|
|
|
{ |
59
|
|
|
parent::__construct(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Execute the console command. |
64
|
|
|
* |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
public function handle() |
68
|
|
|
{ |
69
|
|
|
$data['name_first'] = is_null($this->option('firstname')) ? $this->ask('First Name') : $this->option('firstname'); |
|
|
|
|
70
|
|
|
$data['name_last'] = is_null($this->option('lastname')) ? $this->ask('Last Name') : $this->option('lastname'); |
71
|
|
|
$data['username'] = is_null($this->option('username')) ? $this->ask('Username') : $this->option('username'); |
72
|
|
|
$data['email'] = is_null($this->option('email')) ? $this->ask('Email') : $this->option('email'); |
73
|
|
|
$data['password'] = is_null($this->option('password')) ? $this->secret('Password') : $this->option('password'); |
74
|
|
|
$password_confirmation = is_null($this->option('password')) ? $this->secret('Confirm Password') : $this->option('password'); |
75
|
|
|
|
76
|
|
|
if ($data['password'] !== $password_confirmation) { |
77
|
|
|
return $this->error('The passwords provided did not match!'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin'); |
81
|
|
|
|
82
|
|
|
try { |
83
|
|
|
$user = new UserRepository; |
84
|
|
|
$user->create($data); |
85
|
|
|
|
86
|
|
|
return $this->info('User successfully created.'); |
87
|
|
|
} catch (\Exception $ex) { |
88
|
|
|
return $this->error($ex->getMessage()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.