Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

pterodactyl/panel

8314 stars
2 code files
View pterodactyl/panel on GitHub

app/Services/Users/UserCreationService.php

Open in GitHub
use Ramsey\Uuid\Uuid;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Auth\PasswordBroker;
use Pterodactyl\Notifications\AccountCreated;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
 
class UserCreationService
{
//
public function handle(array $data)
{
if (array_key_exists('password', $data) && !empty($data['password'])) {
$data['password'] = $this->hasher->make($data['password']);
}
 
$this->connection->beginTransaction();
if (!isset($data['password']) || empty($data['password'])) {
$generateResetToken = true;
$data['password'] = $this->hasher->make(str_random(30));
}
 
$user = $this->repository->create(array_merge($data, [
'uuid' => Uuid::uuid4()->toString(),
]), true, true);
 
if (isset($generateResetToken)) {
$token = $this->passwordBroker->createToken($user);
}
 
$this->connection->commit();
$user->notify(new AccountCreated($user, $token ?? null));
 
return $user;
}
}

app/Console/Commands/User/MakeUserCommand.php

Open in GitHub
use Illuminate\Console\Command;
use Pterodactyl\Services\Users\UserCreationService;
 
class MakeUserCommand extends Command
{
public function __construct(UserCreationService $creationService)
{
parent::__construct();
 
$this->creationService = $creationService;
}
 
public function handle()
{
//
$user = $this->creationService->handle(compact('email', 'username', 'name_first', 'name_last', 'password', 'root_admin'));
//
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.