mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Framework: Addressed deprecations
This commit is contained in:
parent
b4b84f81a0
commit
28d6292278
@ -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),
|
||||
],
|
||||
]);
|
||||
|
||||
|
@ -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)
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
return $this->totpService->verifyCode($value, $this->secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return trans('validation.totp');
|
||||
$passes = $this->totpService->verifyCode($value, $this->secret);
|
||||
if (!$passes) {
|
||||
$fail(trans('validation.totp'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user