2017-08-05 00:11:41 +00:00
|
|
|
<?php
|
2022-01-15 16:10:37 +00:00
|
|
|
|
2017-08-05 00:11:41 +00:00
|
|
|
namespace Pterodactyl\Services\Users;
|
|
|
|
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
2017-08-05 00:11:41 +00:00
|
|
|
use Illuminate\Contracts\Translation\Translator;
|
|
|
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class UserDeletionService
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* UserDeletionService constructor.
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected UserRepositoryInterface $repository,
|
|
|
|
protected Translator $translator
|
2017-08-05 00:11:41 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a user from the panel only if they have no servers attached to their account.
|
|
|
|
*
|
2022-10-21 01:17:03 +00:00
|
|
|
* @throws DisplayException
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(int|User $user): ?bool
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
2022-10-21 01:17:03 +00:00
|
|
|
if (is_int($user)) {
|
|
|
|
$user = User::query()->findOrFail($user);
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
|
2022-10-21 01:17:03 +00:00
|
|
|
if ($user->servers()->count() > 0) {
|
2022-01-15 16:10:37 +00:00
|
|
|
throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers'));
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
return $this->repository->delete($user);
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
}
|