MakeUserCommand.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Classes\Pterodactyl;
  4. use App\Models\User;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Hash;
  7. class MakeUserCommand extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'make:user {--ptero_id=} {--password=}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Create an admin account with the Artisan Console';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. $ptero_id = $this->option('ptero_id') ?? $this->ask('Please specify your Pterodactyl ID.');
  38. $password = $this->option('password') ?? $this->ask('Please specify your password.');
  39. if (strlen($password) < 8) {
  40. print_r('Your password need to be at least 8 characters long');
  41. return false;
  42. }
  43. $response = Pterodactyl::getUser($ptero_id);
  44. if (is_null($response)) {
  45. print_r('It seems that your Pterodactyl ID isnt correct. Rerun the command and input an correct ID');
  46. return false;
  47. }
  48. $user = User::create([
  49. 'name' => $response['first_name'],
  50. 'email' => $response['email'],
  51. 'role' => 'admin',
  52. 'password' => Hash::make($password),
  53. 'pterodactyl_id' => $response['id']
  54. ]);
  55. $this->table(['Field', 'Value'], [
  56. ['ID', $user->id],
  57. ['Email', $user->email],
  58. ['Username', $user->name],
  59. ['Ptero-ID', $user->pterodactyl_id],
  60. ['Admin', $user->role],
  61. ]);
  62. return true;
  63. }
  64. }