Skip to content

NOW MANAGED ON CODEBERG

Framework: Addressed deprecations

Dan Brown28d6292278b9
diff --git a/app/Access/Controllers/MfaTotpController.php b/app/Access/Controllers/MfaTotpController.php
index f60644b84..5202fedc0 100644
--- a/app/Access/Controllers/MfaTotpController.php
+++ b/app/Access/Controllers/MfaTotpController.php
@@ -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),
],
]);
diff --git a/app/Access/Mfa/TotpValidationRule.php b/app/Access/Mfa/TotpValidationRule.php
index c38bde90b..63b575f19 100644
--- a/app/Access/Mfa/TotpValidationRule.php
+++ b/app/Access/Mfa/TotpValidationRule.php
@@ -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'));
+ }
}
}
diff --git a/database/migrations/2015_08_31_175240_add_search_indexes.php b/database/migrations/2015_08_31_175240_add_search_indexes.php
index 4e0421e9e..3382b2d54 100644
--- a/database/migrations/2015_08_31_175240_add_search_indexes.php
+++ b/database/migrations/2015_08_31_175240_add_search_indexes.php
@@ -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) {
diff --git a/database/migrations/2015_12_05_145049_fulltext_weighting.php b/database/migrations/2015_12_05_145049_fulltext_weighting.php
index 7f9d2373c..33163e854 100644
--- a/database/migrations/2015_12_05_145049_fulltext_weighting.php
+++ b/database/migrations/2015_12_05_145049_fulltext_weighting.php
@@ -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) {
diff --git a/database/migrations/2017_03_19_091553_create_search_index_table.php b/database/migrations/2017_03_19_091553_create_search_index_table.php
index 72be3ccbe..71f93fa2d 100644
--- a/database/migrations/2017_03_19_091553_create_search_index_table.php
+++ b/database/migrations/2017_03_19_091553_create_search_index_table.php
@@ -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) {