2017-08-05 00:11:41 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-05 00:11:41 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
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-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2017-08-05 00:11:41 +00:00
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class UserDeletionService
|
2017-08-05 00:11:41 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Translation\Translator
|
|
|
|
*/
|
|
|
|
protected $translator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $serverRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DeletionService constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
2019-09-06 04:32:57 +00:00
|
|
|
* @param \Illuminate\Contracts\Translation\Translator $translator
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
|
2017-08-05 00:11:41 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ServerRepositoryInterface $serverRepository,
|
|
|
|
Translator $translator,
|
|
|
|
UserRepositoryInterface $repository
|
|
|
|
) {
|
|
|
|
$this->repository = $repository;
|
|
|
|
$this->translator = $translator;
|
|
|
|
$this->serverRepository = $serverRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a user from the panel only if they have no servers attached to their account.
|
|
|
|
*
|
|
|
|
* @param int|\Pterodactyl\Models\User $user
|
|
|
|
* @return bool|null
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
*/
|
|
|
|
public function handle($user)
|
|
|
|
{
|
2017-08-05 22:20:07 +00:00
|
|
|
if ($user instanceof User) {
|
|
|
|
$user = $user->id;
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 04:49:50 +00:00
|
|
|
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['owner_id', '=', $user]]);
|
2017-08-05 22:23:02 +00:00
|
|
|
if ($servers > 0) {
|
2017-08-05 00:11:41 +00:00
|
|
|
throw new DisplayException($this->translator->trans('admin/user.exceptions.user_has_servers'));
|
|
|
|
}
|
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
return $this->repository->delete($user);
|
2017-08-05 00:11:41 +00:00
|
|
|
}
|
|
|
|
}
|