Merge pull request #153 from ControlPanel-gg/improve_make_user_command
improved the make user command to give better feedback
This commit is contained in:
commit
2293afaad2
|
@ -11,6 +11,7 @@ use Exception;
|
||||||
use Illuminate\Http\Client\PendingRequest;
|
use Illuminate\Http\Client\PendingRequest;
|
||||||
use Illuminate\Http\Client\Response;
|
use Illuminate\Http\Client\Response;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
class Pterodactyl
|
class Pterodactyl
|
||||||
{
|
{
|
||||||
|
@ -34,9 +35,8 @@ class Pterodactyl
|
||||||
*/
|
*/
|
||||||
public function getUser(int $pterodactylId){
|
public function getUser(int $pterodactylId){
|
||||||
$response = self::client()->get("/application/users/{$pterodactylId}");
|
$response = self::client()->get("/application/users/{$pterodactylId}");
|
||||||
if ($response->failed()) {
|
|
||||||
return [];
|
if ($response->failed()) return $response->json();
|
||||||
}
|
|
||||||
return $response->json()['attributes'];
|
return $response->json()['attributes'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ use App\Classes\Pterodactyl;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class MakeUserCommand extends Command
|
class MakeUserCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -46,16 +48,27 @@ class MakeUserCommand extends Command
|
||||||
$ptero_id = $this->option('ptero_id') ?? $this->ask('Please specify your Pterodactyl ID.');
|
$ptero_id = $this->option('ptero_id') ?? $this->ask('Please specify your Pterodactyl ID.');
|
||||||
$password = $this->option('password') ?? $this->ask('Please specify your password.');
|
$password = $this->option('password') ?? $this->ask('Please specify your password.');
|
||||||
|
|
||||||
if (strlen($password) < 8) {
|
// Validate user input
|
||||||
$this->alert('Your password need to be at least 8 characters long');
|
$validator = Validator::make([
|
||||||
|
'ptero_id' => $ptero_id,
|
||||||
|
'password' => $password,
|
||||||
|
], [
|
||||||
|
'ptero_id' => 'required|numeric|integer|min:1|max:2147483647',
|
||||||
|
'password' => 'required|string|min:8|max:60',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
$this->error($validator->errors()->first());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Do something with response (check for status code and give hints based upon that)
|
//TODO: Do something with response (check for status code and give hints based upon that)
|
||||||
$response = $this->pterodactyl->getUser($ptero_id);
|
$response = $this->pterodactyl->getUser($ptero_id);
|
||||||
|
|
||||||
if ($response === []) {
|
if (isset($response['errors'])) {
|
||||||
$this->alert('It seems that your Pterodactyl ID is not correct. Rerun the command and input an correct ID');
|
if (isset($response['errors'][0]['code'])) $this->error("code: {$response['errors'][0]['code']}");
|
||||||
|
if (isset($response['errors'][0]['status'])) $this->error("status: {$response['errors'][0]['status']}");
|
||||||
|
if (isset($response['errors'][0]['detail'])) $this->error("detail: {$response['errors'][0]['detail']}");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,13 +83,12 @@ class UserController extends Controller
|
||||||
"role" => Rule::in(['admin', 'mod', 'client', 'member']),
|
"role" => Rule::in(['admin', 'mod', 'client', 'member']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (empty($this->pterodactyl->getUser($request->input('pterodactyl_id')))) {
|
if (isset($this->pterodactyl->getUser($request->input('pterodactyl_id'))['errors'])) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'pterodactyl_id' => ["User does not exists on pterodactyl's panel"]
|
'pterodactyl_id' => ["User does not exists on pterodactyl's panel"]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!is_null($request->input('new_password'))) {
|
if (!is_null($request->input('new_password'))) {
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'new_password' => 'required|string|min:8',
|
'new_password' => 'required|string|min:8',
|
||||||
|
|
Loading…
Reference in a new issue