Remove recovery token repository

This commit is contained in:
Lance Pioch 2024-03-16 19:28:25 -04:00
parent a496be67b8
commit 191e0adc58
2 changed files with 4 additions and 18 deletions

View File

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

View File

@ -2,13 +2,13 @@
namespace App\Services\Users; namespace App\Services\Users;
use App\Models\RecoveryToken;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Models\User; use App\Models\User;
use PragmaRX\Google2FA\Google2FA; use PragmaRX\Google2FA\Google2FA;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Encryption\Encrypter; use Illuminate\Contracts\Encryption\Encrypter;
use App\Repositories\Eloquent\RecoveryTokenRepository;
use App\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid; use App\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid;
class ToggleTwoFactorService class ToggleTwoFactorService
@ -20,7 +20,6 @@ class ToggleTwoFactorService
private ConnectionInterface $connection, private ConnectionInterface $connection,
private Encrypter $encrypter, private Encrypter $encrypter,
private Google2FA $google2FA, private Google2FA $google2FA,
private RecoveryTokenRepository $recoveryTokenRepository,
) { ) {
} }
@ -68,12 +67,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);
} }
$user->totp_authenticated_at = now(); $user->totp_authenticated_at = now();