Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
90 lines
2.5 KiB
PHP
90 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Laravel\Fortify;
|
|
|
|
use BaconQrCode\Renderer\Color\Rgb;
|
|
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
|
|
use BaconQrCode\Renderer\ImageRenderer;
|
|
use BaconQrCode\Renderer\RendererStyle\Fill;
|
|
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
|
use BaconQrCode\Writer;
|
|
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider;
|
|
use Laravel\Fortify\Events\RecoveryCodeReplaced;
|
|
|
|
trait TwoFactorAuthenticatable
|
|
{
|
|
/**
|
|
* Determine if two-factor authentication has been enabled.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasEnabledTwoFactorAuthentication()
|
|
{
|
|
if (Fortify::confirmsTwoFactorAuthentication()) {
|
|
return ! is_null($this->two_factor_secret) &&
|
|
! is_null($this->two_factor_confirmed_at);
|
|
}
|
|
|
|
return ! is_null($this->two_factor_secret);
|
|
}
|
|
|
|
/**
|
|
* Get the user's two factor authentication recovery codes.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function recoveryCodes()
|
|
{
|
|
return json_decode(Fortify::currentEncrypter()->decrypt($this->two_factor_recovery_codes), true);
|
|
}
|
|
|
|
/**
|
|
* Replace the given recovery code with a new one in the user's stored codes.
|
|
*
|
|
* @param string $code
|
|
* @return void
|
|
*/
|
|
public function replaceRecoveryCode($code)
|
|
{
|
|
$this->forceFill([
|
|
'two_factor_recovery_codes' => Fortify::currentEncrypter()->encrypt(str_replace(
|
|
$code,
|
|
RecoveryCode::generate(),
|
|
Fortify::currentEncrypter()->decrypt($this->two_factor_recovery_codes)
|
|
)),
|
|
])->save();
|
|
|
|
RecoveryCodeReplaced::dispatch($this, $code);
|
|
}
|
|
|
|
/**
|
|
* Get the QR code SVG of the user's two factor authentication QR code URL.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function twoFactorQrCodeSvg()
|
|
{
|
|
$svg = (new Writer(
|
|
new ImageRenderer(
|
|
new RendererStyle(192, 0, null, null, Fill::uniformColor(new Rgb(255, 255, 255), new Rgb(45, 55, 72))),
|
|
new SvgImageBackEnd
|
|
)
|
|
))->writeString($this->twoFactorQrCodeUrl());
|
|
|
|
return trim(substr($svg, strpos($svg, "\n") + 1));
|
|
}
|
|
|
|
/**
|
|
* Get the two factor authentication QR code URL.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function twoFactorQrCodeUrl()
|
|
{
|
|
return app(TwoFactorAuthenticationProvider::class)->qrCodeUrl(
|
|
config('app.name'),
|
|
$this->{Fortify::username()},
|
|
Fortify::currentEncrypter()->decrypt($this->two_factor_secret)
|
|
);
|
|
}
|
|
}
|