]> BookStack Code Mirror - bookstack/commitdiff
Framework: Addressed deprecations 4903/head
authorDan Brown <redacted>
Sun, 17 Mar 2024 16:52:19 +0000 (16:52 +0000)
committerDan Brown <redacted>
Sun, 17 Mar 2024 16:52:19 +0000 (16:52 +0000)
app/Access/Controllers/MfaTotpController.php
app/Access/Mfa/TotpValidationRule.php
database/migrations/2015_08_31_175240_add_search_indexes.php
database/migrations/2015_12_05_145049_fulltext_weighting.php
database/migrations/2017_03_19_091553_create_search_index_table.php

index f60644b84cc043b4445cd9339ec5738b2106de27..5202fedc04f925c09c36a0d1e1720ea7c4b4158d 100644 (file)
@@ -19,20 +19,25 @@ class MfaTotpController extends Controller
 
     protected const SETUP_SECRET_SESSION_KEY = 'mfa-setup-totp-secret';
 
+    public function __construct(
+        protected TotpService $totp
+    ) {
+    }
+
     /**
      * Show a view that generates and displays a TOTP QR code.
      */
-    public function generate(TotpService $totp)
+    public function generate()
     {
         if (session()->has(static::SETUP_SECRET_SESSION_KEY)) {
             $totpSecret = decrypt(session()->get(static::SETUP_SECRET_SESSION_KEY));
         } else {
-            $totpSecret = $totp->generateSecret();
+            $totpSecret = $this->totp->generateSecret();
             session()->put(static::SETUP_SECRET_SESSION_KEY, encrypt($totpSecret));
         }
 
-        $qrCodeUrl = $totp->generateUrl($totpSecret, $this->currentOrLastAttemptedUser());
-        $svg = $totp->generateQrCodeSvg($qrCodeUrl);
+        $qrCodeUrl = $this->totp->generateUrl($totpSecret, $this->currentOrLastAttemptedUser());
+        $svg = $this->totp->generateQrCodeSvg($qrCodeUrl);
 
         $this->setPageTitle(trans('auth.mfa_gen_totp_title'));
 
@@ -56,7 +61,7 @@ class MfaTotpController extends Controller
             'code' => [
                 'required',
                 'max:12', 'min:4',
-                new TotpValidationRule($totpSecret),
+                new TotpValidationRule($totpSecret, $this->totp),
             ],
         ]);
 
@@ -87,7 +92,7 @@ class MfaTotpController extends Controller
             'code' => [
                 'required',
                 'max:12', 'min:4',
-                new TotpValidationRule($totpSecret),
+                new TotpValidationRule($totpSecret, $this->totp),
             ],
         ]);
 
index c38bde90b75dc6249d3ec093602d9c721e4377ba..63b575f198b80c16e0f7119f2f22c5a31d357bf3 100644 (file)
@@ -2,36 +2,26 @@
 
 namespace BookStack\Access\Mfa;
 
-use Illuminate\Contracts\Validation\Rule;
+use Closure;
+use Illuminate\Contracts\Validation\ValidationRule;
 
-class TotpValidationRule implements Rule
+class TotpValidationRule implements ValidationRule
 {
-    protected $secret;
-    protected $totpService;
-
     /**
      * Create a new rule instance.
      * Takes the TOTP secret that must be system provided, not user provided.
      */
-    public function __construct(string $secret)
-    {
-        $this->secret = $secret;
-        $this->totpService = app()->make(TotpService::class);
+    public function __construct(
+        protected string $secret,
+        protected TotpService $totpService,
+    ) {
     }
 
-    /**
-     * Determine if the validation rule passes.
-     */
-    public function passes($attribute, $value)
-    {
-        return $this->totpService->verifyCode($value, $this->secret);
-    }
-
-    /**
-     * Get the validation error message.
-     */
-    public function message()
+    public function validate(string $attribute, mixed $value, Closure $fail): void
     {
-        return trans('validation.totp');
+        $passes = $this->totpService->verifyCode($value, $this->secret);
+        if (!$passes) {
+            $fail(trans('validation.totp'));
+        }
     }
 }
index 4e0421e9e95ecce25bf53cca714a341b8bfc8fe1..3382b2d5495f9043c5fe2d095a5c213e042a5f96 100644 (file)
@@ -26,9 +26,9 @@ return new class extends Migration
     public function down(): void
     {
         $sm = Schema::getConnection()->getDoctrineSchemaManager();
-        $pages = $sm->listTableDetails('pages');
-        $books = $sm->listTableDetails('books');
-        $chapters = $sm->listTableDetails('chapters');
+        $pages = $sm->introspectTable('pages');
+        $books = $sm->introspectTable('books');
+        $chapters = $sm->introspectTable('chapters');
 
         if ($pages->hasIndex('search')) {
             Schema::table('pages', function (Blueprint $table) {
index 7f9d2373c5ca505f86f8d953104ffc58c4e2e1d3..33163e8544606dd3527535605dd0d59d946c0306 100644 (file)
@@ -26,9 +26,9 @@ return new class extends Migration
     public function down(): void
     {
         $sm = Schema::getConnection()->getDoctrineSchemaManager();
-        $pages = $sm->listTableDetails('pages');
-        $books = $sm->listTableDetails('books');
-        $chapters = $sm->listTableDetails('chapters');
+        $pages = $sm->introspectTable('pages');
+        $books = $sm->introspectTable('books');
+        $chapters = $sm->introspectTable('chapters');
 
         if ($pages->hasIndex('name_search')) {
             Schema::table('pages', function (Blueprint $table) {
index 72be3ccbe0c7c7dd8636b585e6e405434f5cd4a4..71f93fa2d6214715a8f62ba84899bf81220a0c9e 100644 (file)
@@ -25,9 +25,9 @@ return new class extends Migration
         });
 
         $sm = Schema::getConnection()->getDoctrineSchemaManager();
-        $pages = $sm->listTableDetails('pages');
-        $books = $sm->listTableDetails('books');
-        $chapters = $sm->listTableDetails('chapters');
+        $pages = $sm->introspectTable('pages');
+        $books = $sm->introspectTable('books');
+        $chapters = $sm->introspectTable('chapters');
 
         if ($pages->hasIndex('search')) {
             Schema::table('pages', function (Blueprint $table) {
Morty Proxy This is a proxified and sanitized view of the page, visit original site.