Skip to content

Commit

Permalink
[2.x] New version
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Mar 5, 2024
1 parent 7993282 commit 12ff219
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 29 deletions.
2 changes: 0 additions & 2 deletions src/Http/Controllers/ConfirmTwoFactorCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;

use function now;
use function response;
use function trans;

use const INF;

class ConfirmTwoFactorCodeController extends Controller
Expand Down
1 change: 0 additions & 1 deletion src/Http/Middleware/ConfirmTwoFactorCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Closure;
use Illuminate\Http\Request;
use Laragear\TwoFactor\Contracts\TwoFactorAuthenticatable as TwoFactor;

use function config;
use function now;
use function response;
Expand Down
1 change: 0 additions & 1 deletion src/Http/Middleware/RequireTwoFactorEnabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Closure;
use Illuminate\Http\Request;
use Laragear\TwoFactor\Contracts\TwoFactorAuthenticatable as TwoFactor;

use function response;
use function trans;

Expand Down
1 change: 0 additions & 1 deletion src/Models/Concerns/HandlesCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Support\Carbon;
use ParagonIE\ConstantTime\Base32;

use function cache;
use function config;
use function floor;
Expand Down
1 change: 0 additions & 1 deletion src/Models/Concerns/HandlesRecoveryCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Collection;
use Illuminate\Support\Str;

use function is_int;
use function now;
use function strtoupper;
Expand Down
1 change: 0 additions & 1 deletion src/Models/Concerns/SerializesSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;
use InvalidArgumentException;

use function array_values;
use function chunk_split;
use function config;
Expand Down
21 changes: 10 additions & 11 deletions src/Models/TwoFactorAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Laragear\TwoFactor\Contracts\TwoFactorTotp;
use ParagonIE\ConstantTime\Base32;

use function array_merge;
use function config;
use function json_encode;
Expand All @@ -28,7 +27,7 @@
* @property int $window
* @property string $algorithm
* @property array $totp_config
* @property \Illuminate\Support\Collection<int, array{code: string, used_at: \Illuminate\Support\Carbon}>|null $recovery_codes
* @property \Illuminate\Support\Collection<int, array{code: string, used_at: \Illuminate\Support\Carbon|null}>|null $recovery_codes
* @property \Illuminate\Support\Collection<int, array{"2fa_remember": string, ip: string, added_at: integer}>|null $safe_devices
* @property \Illuminate\Support\Carbon|\DateTimeInterface|null $enabled_at
* @property \Illuminate\Support\Carbon|\DateTimeInterface|null $recovery_codes_generated_at
Expand All @@ -51,21 +50,21 @@ class TwoFactorAuthentication extends Model implements TwoFactorTotp
* @var array
*/
protected $casts = [
'shared_secret' => 'encrypted',
'authenticatable_id' => 'int',
'digits' => 'int',
'seconds' => 'int',
'window' => 'int',
'recovery_codes' => 'encrypted:collection',
'safe_devices' => 'collection',
'enabled_at' => 'datetime',
'shared_secret' => 'encrypted',
'authenticatable_id' => 'int',
'digits' => 'int',
'seconds' => 'int',
'window' => 'int',
'recovery_codes' => 'encrypted:collection',
'safe_devices' => 'collection',
'enabled_at' => 'datetime',
'recovery_codes_generated_at' => 'datetime',
];

/**
* The attributes that are mass assignable.
*
* @var array<string>
* @var array<int, string>
*/
protected $fillable = ['digits', 'seconds', 'window', 'algorithm'];

Expand Down
1 change: 0 additions & 1 deletion src/Rules/Totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Arr;
use Laragear\TwoFactor\Contracts\TwoFactorAuthenticatable;

use function is_string;

/**
Expand Down
1 change: 0 additions & 1 deletion src/TwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Http\Request;
use Laragear\TwoFactor\Contracts\TwoFactorAuthenticatable;
use Laragear\TwoFactor\Exceptions\InvalidCodeException;

use function app;
use function trans;
use function validator;
Expand Down
5 changes: 2 additions & 3 deletions src/TwoFactorAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;

use function collect;
use function config;
use function cookie;
Expand Down Expand Up @@ -213,8 +212,8 @@ public function addSafeDevice(Request $request): string
$this->twoFactorAuth->safe_devices = $this->safeDevices()
->push([
'2fa_remember' => $token = $this->generateTwoFactorRemember(),
'ip' => $request->ip(),
'added_at' => $this->freshTimestamp()->getTimestamp(),
'ip' => $request->ip(),
'added_at' => $this->freshTimestamp()->getTimestamp(),
])
->sortByDesc('added_at') // Ensure the last is the first, so we can slice it.
->slice(0, config('two-factor.safe_devices.max_devices', 3))
Expand Down
1 change: 0 additions & 1 deletion src/TwoFactorLoginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Illuminate\Support\Facades\Crypt;
use InvalidArgumentException;
use Laragear\TwoFactor\Exceptions\InvalidCodeException;

use function array_merge;
use function response;
use function view;
Expand Down
5 changes: 3 additions & 2 deletions src/TwoFactorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ protected function publishMigrations(): void

$files = Collection::make(File::files(static::MIGRATIONS))
->mapWithKeys(fn (SplFileInfo $file): array => [
$file->getRealPath() => Str::of($file->getFileName())
$file->getRealPath() =>
Str::of($file->getFileName())
->after('0000_00_00_000000')
->prepend($now->addSecond()->format('Y_m_d_His'))
->prepend('/')
->prepend($this->app->databasePath('migrations'))
->toString(),
->toString()
]);

$this->publishes($files->toArray(), 'migrations');
Expand Down
1 change: 0 additions & 1 deletion tests/Rules/TotpRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Tests\CreatesTwoFactorUser;
use Tests\Stubs\UserStub;
use Tests\TestCase;

use function validator;

#[WithMigration]
Expand Down
1 change: 0 additions & 1 deletion tests/TwoFactorLoginHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Orchestra\Testbench\Attributes\WithMigration;
use Tests\Stubs\UserStub;
use Tests\Stubs\UserTwoFactorStub;

use function app;
use function config;
use function get_class;
Expand Down
1 change: 0 additions & 1 deletion tests/TwoFactorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Orchestra\Testbench\Attributes\WithMigration;
use Tests\Stubs\UserStub;
use Tests\Stubs\UserTwoFactorStub;

use function now;

#[WithMigration]
Expand Down

0 comments on commit 12ff219

Please sign in to comment.