Remove repositories and replace usages
This commit is contained in:
parent
860b2d890b
commit
369c61f1a8
11 changed files with 49 additions and 93 deletions
|
@ -8,7 +8,6 @@ use Pterodactyl\Models\User;
|
|||
use PragmaRX\Google2FA\Google2FA;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Repositories\Eloquent\RecoveryTokenRepository;
|
||||
use Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid;
|
||||
|
||||
|
@ -21,8 +20,7 @@ class ToggleTwoFactorService
|
|||
private ConnectionInterface $connection,
|
||||
private Encrypter $encrypter,
|
||||
private Google2FA $google2FA,
|
||||
private RecoveryTokenRepository $recoveryTokenRepository,
|
||||
private UserRepositoryInterface $repository
|
||||
private RecoveryTokenRepository $recoveryTokenRepository
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -78,10 +76,9 @@ class ToggleTwoFactorService
|
|||
$this->recoveryTokenRepository->insert($inserts);
|
||||
}
|
||||
|
||||
$this->repository->withoutFreshModel()->update($user->id, [
|
||||
'totp_authenticated_at' => Carbon::now(),
|
||||
'use_totp' => (is_null($toggleState) ? !$user->use_totp : $toggleState),
|
||||
]);
|
||||
$user->totp_authenticated_at = now();
|
||||
$user->use_totp = (is_null($toggleState) ? !$user->use_totp : $toggleState);
|
||||
$user->save();
|
||||
|
||||
return $tokens;
|
||||
});
|
||||
|
|
|
@ -6,7 +6,6 @@ use Exception;
|
|||
use RuntimeException;
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
|
||||
class TwoFactorSetupService
|
||||
|
@ -18,8 +17,7 @@ class TwoFactorSetupService
|
|||
*/
|
||||
public function __construct(
|
||||
private ConfigRepository $config,
|
||||
private Encrypter $encrypter,
|
||||
private UserRepositoryInterface $repository
|
||||
private Encrypter $encrypter
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -27,9 +25,6 @@ class TwoFactorSetupService
|
|||
* Generate a 2FA token and store it in the database before returning the
|
||||
* QR code URL. This URL will need to be attached to a QR generating service in
|
||||
* order to function.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function handle(User $user): array
|
||||
{
|
||||
|
@ -42,9 +37,8 @@ class TwoFactorSetupService
|
|||
throw new RuntimeException($exception->getMessage(), 0, $exception);
|
||||
}
|
||||
|
||||
$this->repository->withoutFreshModel()->update($user->id, [
|
||||
'totp_secret' => $this->encrypter->encrypt($secret),
|
||||
]);
|
||||
$user->totp_secret = $this->encrypter->encrypt($secret);
|
||||
$user->save();
|
||||
|
||||
$company = urlencode(preg_replace('/\s/', '', $this->config->get('app.name')));
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use Illuminate\Contracts\Hashing\Hasher;
|
|||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Pterodactyl\Notifications\AccountCreated;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Model\DataValidationException;
|
||||
|
||||
class UserCreationService
|
||||
{
|
||||
|
@ -18,8 +18,7 @@ class UserCreationService
|
|||
public function __construct(
|
||||
private ConnectionInterface $connection,
|
||||
private Hasher $hasher,
|
||||
private PasswordBroker $passwordBroker,
|
||||
private UserRepositoryInterface $repository
|
||||
private PasswordBroker $passwordBroker
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -27,7 +26,7 @@ class UserCreationService
|
|||
* Create a new user on the system.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws DataValidationException
|
||||
*/
|
||||
public function handle(array $data): User
|
||||
{
|
||||
|
@ -36,15 +35,17 @@ class UserCreationService
|
|||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
if (!isset($data['password']) || empty($data['password'])) {
|
||||
if (empty($data['password'])) {
|
||||
$generateResetToken = true;
|
||||
$data['password'] = $this->hasher->make(str_random(30));
|
||||
}
|
||||
|
||||
/** @var \Pterodactyl\Models\User $user */
|
||||
$user = $this->repository->create(array_merge($data, [
|
||||
// /** @var User $user */
|
||||
// $user = $this->repository->create($data, true, true);
|
||||
|
||||
$user = User::query()->forceCreate(array_merge($data, [
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
]), true, true);
|
||||
]));
|
||||
|
||||
if (isset($generateResetToken)) {
|
||||
$token = $this->passwordBroker->createToken($user);
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Pterodactyl\Services\Users;
|
|||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class UserDeletionService
|
||||
|
@ -14,7 +13,6 @@ class UserDeletionService
|
|||
* UserDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected UserRepositoryInterface $repository,
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected Translator $translator
|
||||
) {
|
||||
|
@ -23,19 +21,19 @@ class UserDeletionService
|
|||
/**
|
||||
* Delete a user from the panel only if they have no servers attached to their account.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws DisplayException
|
||||
*/
|
||||
public function handle(int|User $user): ?bool
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$user = $user->id;
|
||||
if (is_int($user)) {
|
||||
$user = User::query()->findOrFail($user);
|
||||
}
|
||||
|
||||
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['owner_id', '=', $user]]);
|
||||
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['owner_id', '=', $user->id]]);
|
||||
if ($servers > 0) {
|
||||
throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($user);
|
||||
return $user->delete();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue