Compare commits

...

1 commit

Author SHA1 Message Date
Lance Pioch
706dd6523e Replace recovery token repository 2022-10-22 20:06:44 -04:00
2 changed files with 4 additions and 18 deletions

View file

@ -1,13 +0,0 @@
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\RecoveryToken;
class RecoveryTokenRepository extends EloquentRepository
{
public function model(): string
{
return RecoveryToken::class;
}
}

View file

@ -6,10 +6,10 @@ use Carbon\Carbon;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use PragmaRX\Google2FA\Google2FA; use PragmaRX\Google2FA\Google2FA;
use Pterodactyl\Models\RecoveryToken;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Encryption\Encrypter; use Illuminate\Contracts\Encryption\Encrypter;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface; use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Repositories\Eloquent\RecoveryTokenRepository;
use Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid; use Pterodactyl\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid;
class ToggleTwoFactorService class ToggleTwoFactorService
@ -21,7 +21,6 @@ class ToggleTwoFactorService
private ConnectionInterface $connection, private ConnectionInterface $connection,
private Encrypter $encrypter, private Encrypter $encrypter,
private Google2FA $google2FA, private Google2FA $google2FA,
private RecoveryTokenRepository $recoveryTokenRepository,
private UserRepositoryInterface $repository private UserRepositoryInterface $repository
) { ) {
} }
@ -70,12 +69,12 @@ class ToggleTwoFactorService
$tokens[] = $token; $tokens[] = $token;
} }
// Before inserting any new records make sure all of the old ones are deleted to avoid // Before inserting any new records make sure all the old ones are deleted to avoid
// any issues or storing an unnecessary number of tokens in the database. // any issues or storing an unnecessary number of tokens in the database.
$this->recoveryTokenRepository->deleteWhere(['user_id' => $user->id]); $user->recoveryTokens()->delete();
// Bulk insert the hashed tokens. // Bulk insert the hashed tokens.
$this->recoveryTokenRepository->insert($inserts); RecoveryToken::query()->insert($inserts);
} }
$this->repository->withoutFreshModel()->update($user->id, [ $this->repository->withoutFreshModel()->update($user->id, [