Phase 0: Fundament für Inhaus
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>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

21
vendor/laravel/fortify/LICENSE.md vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

35
vendor/laravel/fortify/README.md vendored Normal file
View file

@ -0,0 +1,35 @@
<p align="center">
<img alt="Fortify Logo Dark Mode" src="/art/fortify-light.svg#gh-light-mode-only"/>
<img alt="Fortify Logo Dark Mode" src="/art/fortify-dark.svg#gh-dark-mode-only"/>
</p>
<p align="center">
<a href="https://github.com/laravel/fortify/actions"><img src="https://github.com/laravel/fortify/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/fortify"><img src="https://img.shields.io/packagist/dt/laravel/fortify" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/fortify"><img src="https://img.shields.io/packagist/v/laravel/fortify" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/fortify"><img src="https://img.shields.io/packagist/l/laravel/fortify" alt="License"></a>
</p>
## Introduction
Laravel Fortify is a frontend agnostic authentication backend for Laravel. Fortify powers the registration, authentication, and two-factor authentication features of [Laravel Starter Kits](https://laravel.com/starter-kits).
## Official Documentation
Documentation for Fortify can be found on the [Laravel website](https://laravel.com/docs/fortify).
## Contributing
Thank you for considering contributing to Fortify! You can read the contribution guide [here](.github/CONTRIBUTING.md).
## Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
## Security Vulnerabilities
Please review [our security policy](https://github.com/laravel/fortify/security/policy) on how to report security vulnerabilities.
## License
Laravel Fortify is open-sourced software licensed under the [MIT license](LICENSE.md).

63
vendor/laravel/fortify/composer.json vendored Normal file
View file

@ -0,0 +1,63 @@
{
"name": "laravel/fortify",
"description": "Backend controllers and scaffolding for Laravel authentication.",
"keywords": ["laravel", "auth"],
"license": "MIT",
"support": {
"issues": "https://github.com/laravel/fortify/issues",
"source": "https://github.com/laravel/fortify"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"require": {
"php": "^8.2",
"ext-json": "*",
"bacon/bacon-qr-code": "^3.0",
"illuminate/console": "^11.0|^12.0|^13.0",
"illuminate/support": "^11.0|^12.0|^13.0",
"laravel/passkeys": "^0.2.0",
"pragmarx/google2fa": "^9.0"
},
"require-dev": {
"orchestra/testbench": "^9.15|^10.8|^11.0",
"phpstan/phpstan": "^2.2.6"
},
"autoload": {
"psr-4": {
"Laravel\\Fortify\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Laravel\\Fortify\\Tests\\": "tests/",
"App\\": "workbench/app/",
"Database\\Factories\\": "workbench/database/factories/"
},
"classmap": ["stubs/"]
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
},
"laravel": {
"providers": [
"Laravel\\Fortify\\FortifyServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": "@prepare",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"lint": "@php vendor/bin/phpstan analyse",
"test": "@php vendor/bin/phpunit"
}
}

View file

@ -0,0 +1,86 @@
<?php
use Laravel\Fortify\Features;
return [
'guard' => 'web',
'middleware' => ['web'],
'auth_middleware' => 'auth',
'passwords' => 'users',
'username' => 'email',
'email' => 'email',
'views' => true,
'home' => '/home',
'prefix' => '',
'domain' => null,
'lowercase_usernames' => false,
'limiters' => [
'login' => null,
'passkeys' => null,
],
'paths' => [
'login' => null,
'logout' => null,
'password' => [
'request' => null,
'reset' => null,
'email' => null,
'update' => null,
'confirm' => null,
'confirmation' => null,
],
'register' => null,
'verification' => [
'notice' => null,
'verify' => null,
'send' => null,
],
'user-profile-information' => [
'update' => null,
],
'user-password' => [
'update' => null,
],
'two-factor' => [
'login' => null,
'enable' => null,
'confirm' => null,
'disable' => null,
'qr-code' => null,
'secret-key' => null,
'recovery-codes' => null,
],
'passkey' => [
'login-options' => null,
'login' => null,
'confirm-options' => null,
'confirm' => null,
'registration-options' => null,
'store' => null,
'destroy' => null,
],
],
'redirects' => [
'login' => null,
'logout' => null,
'password-confirmation' => null,
'register' => null,
'email-verification' => null,
'password-reset' => null,
],
'passkeys' => [
'relying_party_id' => parse_url(config('app.url'), PHP_URL_HOST),
'allowed_origins' => [config('app.url')],
'user_handle_secret' => env('PASSKEYS_USER_HANDLE_SECRET', config('app.key')),
'timeout' => 60000,
],
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication(),
Features::passkeys(),
],
];

View file

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->text('two_factor_secret')
->after('password')
->nullable();
$table->text('two_factor_recovery_codes')
->after('two_factor_secret')
->nullable();
$table->timestamp('two_factor_confirmed_at')
->after('two_factor_recovery_codes')
->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn([
'two_factor_secret',
'two_factor_recovery_codes',
'two_factor_confirmed_at',
]);
});
}
};

View file

@ -0,0 +1,151 @@
---
name: fortify-development
description: 'ACTIVATE when the user works on authentication in Laravel. This includes login, registration, password reset, email verification, two-factor authentication (2FA/TOTP/QR codes/recovery codes), passkeys, profile updates, password confirmation, or any auth-related routes and controllers. Activate when the user mentions Fortify, auth, authentication, login, register, signup, forgot password, verify email, 2FA, passkeys, WebAuthn, or references app/Actions/Fortify/, CreateNewUser, UpdateUserProfileInformation, FortifyServiceProvider, config/fortify.php, or auth guards. Fortify is the frontend-agnostic authentication backend for Laravel that registers all auth routes and controllers. Also activate when building SPA or headless authentication, customizing login redirects, overriding response contracts like LoginResponse, or configuring login throttling. Do NOT activate for Laravel Passport (OAuth2 API tokens), Socialite (OAuth social login), or non-auth Laravel features.'
license: MIT
metadata:
author: laravel
---
# Laravel Fortify Development
Fortify is a headless authentication backend that provides authentication routes and controllers for Laravel applications.
## Documentation
Use `search-docs` for detailed Laravel Fortify patterns and documentation.
## Usage
- **Routes**: Use `list-routes` with `only_vendor: true` and `action: "Fortify"` to see all registered endpoints
- **Actions**: Check `app/Actions/Fortify/` for customizable business logic (user creation, password validation, etc.)
- **Config**: See `config/fortify.php` for all options including features, guards, rate limiters, and username field
- **Contracts**: Look in `Laravel\Fortify\Contracts\` for overridable response classes (`LoginResponse`, `LogoutResponse`, etc.)
- **Views**: All view callbacks are set in `FortifyServiceProvider::boot()` using `Fortify::loginView()`, `Fortify::registerView()`, etc.
## Available Features
Enable in `config/fortify.php` features array:
- `Features::registration()` - User registration
- `Features::resetPasswords()` - Password reset via email
- `Features::emailVerification()` - Requires User to implement `MustVerifyEmail`
- `Features::updateProfileInformation()` - Profile updates
- `Features::updatePasswords()` - Password changes
- `Features::twoFactorAuthentication()` - 2FA with QR codes and recovery codes
- `Features::passkeys()` - Passwordless authentication with WebAuthn passkeys
> Use `search-docs` for feature configuration options and customization patterns.
## Setup Workflows
### Two-Factor Authentication Setup
```
- [ ] Add TwoFactorAuthenticatable trait to User model
- [ ] Enable feature in config/fortify.php
- [ ] If the `*_add_two_factor_columns_to_users_table.php` migration is missing, publish via `php artisan vendor:publish --tag=fortify-migrations` and migrate
- [ ] Set up view callbacks in FortifyServiceProvider
- [ ] Create 2FA management UI
- [ ] Test QR code and recovery codes
```
> Use `search-docs` for TOTP implementation and recovery code handling patterns.
### Passkeys Setup
```
- [ ] Add PasskeyAuthenticatable trait to User model and implement PasskeyUser
- [ ] Enable passkeys feature in config/fortify.php
- [ ] If the passkeys table migration is missing, publish via `php artisan vendor:publish --tag=fortify-migrations` and migrate
- [ ] Configure passkeys relying_party_id, allowed_origins, user_handle_secret, and timeout if defaults are not suitable
- [ ] Build UI with @laravel/passkeys for registration, login, confirmation, and deletion
```
> Use `search-docs` for passkey configuration options. For `@laravel/passkeys` frontend usage, refer to the package's README on npm.
### Email Verification Setup
```
- [ ] Enable emailVerification feature in config
- [ ] Implement MustVerifyEmail interface on User model
- [ ] Set up verifyEmailView callback
- [ ] Add verified middleware to protected routes
- [ ] Test verification email flow
```
> Use `search-docs` for MustVerifyEmail implementation patterns.
### Password Reset Setup
```
- [ ] Enable resetPasswords feature in config
- [ ] Set up requestPasswordResetLinkView callback
- [ ] Set up resetPasswordView callback
- [ ] Define password.reset named route (if views disabled)
- [ ] Test reset email and link flow
```
> Use `search-docs` for custom password reset flow patterns.
### SPA Authentication Setup
```
- [ ] Set 'views' => false in config/fortify.php
- [ ] Install and configure Laravel Sanctum for session-based SPA authentication
- [ ] Use the 'web' guard in config/fortify.php (required for session-based authentication)
- [ ] Set up CSRF token handling
- [ ] Test XHR authentication flows
```
> Use `search-docs` for integration and SPA authentication patterns.
#### Two-Factor Authentication in SPA Mode
When `views` is set to `false`, Fortify returns JSON responses instead of redirects.
If a user attempts to log in and two-factor authentication is enabled, the login request will return a JSON response indicating that a two-factor challenge is required:
```json
{
"two_factor": true
}
```
## Best Practices
### Custom Authentication Logic
Override authentication behavior using `Fortify::authenticateUsing()` for custom user retrieval or `Fortify::authenticateThrough()` to customize the authentication pipeline. Override response contracts in `AppServiceProvider` for custom redirects.
### Registration Customization
Modify `app/Actions/Fortify/CreateNewUser.php` to customize user creation logic, validation rules, and additional fields.
### Rate Limiting
Configure via `fortify.limiters.login` in config. Default configuration throttles by username + IP combination.
## Key Endpoints
| Feature | Method | Endpoint |
|------------------------|----------|---------------------------------------------|
| Login | POST | `/login` |
| Logout | POST | `/logout` |
| Register | POST | `/register` |
| Password Reset Request | POST | `/forgot-password` |
| Password Reset | POST | `/reset-password` |
| Email Verify Notice | GET | `/email/verify` |
| Resend Verification | POST | `/email/verification-notification` |
| Password Confirm | POST | `/user/confirm-password` |
| Enable 2FA | POST | `/user/two-factor-authentication` |
| Confirm 2FA | POST | `/user/confirmed-two-factor-authentication` |
| 2FA Challenge | POST | `/two-factor-challenge` |
| Get QR Code | GET | `/user/two-factor-qr-code` |
| Recovery Codes | GET/POST | `/user/two-factor-recovery-codes` |
| Passkey Login Options | GET | `/passkeys/login/options` |
| Passkey Login | POST | `/passkeys/login` |
| Passkey Confirm Options| GET | `/passkeys/confirm/options` |
| Passkey Confirm | POST | `/passkeys/confirm` |
| Passkey Options | GET | `/user/passkeys/options` |
| Register Passkey | POST | `/user/passkeys` |
| Delete Passkey | DELETE | `/user/passkeys/{passkey}` |

221
vendor/laravel/fortify/routes/routes.php vendored Normal file
View file

@ -0,0 +1,221 @@
<?php
use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Features;
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\ConfirmablePasswordController;
use Laravel\Fortify\Http\Controllers\ConfirmedPasswordStatusController;
use Laravel\Fortify\Http\Controllers\ConfirmedTwoFactorAuthenticationController;
use Laravel\Fortify\Http\Controllers\EmailVerificationNotificationController;
use Laravel\Fortify\Http\Controllers\EmailVerificationPromptController;
use Laravel\Fortify\Http\Controllers\NewPasswordController;
use Laravel\Fortify\Http\Controllers\PasswordController;
use Laravel\Fortify\Http\Controllers\PasswordResetLinkController;
use Laravel\Fortify\Http\Controllers\ProfileInformationController;
use Laravel\Fortify\Http\Controllers\RecoveryCodeController;
use Laravel\Fortify\Http\Controllers\RegisteredUserController;
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController;
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticationController;
use Laravel\Fortify\Http\Controllers\TwoFactorQrCodeController;
use Laravel\Fortify\Http\Controllers\TwoFactorSecretKeyController;
use Laravel\Fortify\Http\Controllers\VerifyEmailController;
use Laravel\Fortify\RoutePath;
use Laravel\Passkeys\Http\Controllers\PasskeyConfirmationController;
use Laravel\Passkeys\Http\Controllers\PasskeyLoginController;
use Laravel\Passkeys\Http\Controllers\PasskeyRegistrationController;
Route::group(['middleware' => config('fortify.middleware', ['web'])], function () {
$enableViews = config('fortify.views', true);
// Authentication...
if ($enableViews) {
Route::get(RoutePath::for('login', '/login'), [AuthenticatedSessionController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('login');
}
$limiter = config('fortify.limiters.login');
$twoFactorLimiter = config('fortify.limiters.two-factor');
$passkeyLimiter = config('fortify.limiters.passkeys');
$verificationLimiter = config('fortify.limiters.verification', '6,1');
Route::post(RoutePath::for('login', '/login'), [AuthenticatedSessionController::class, 'store'])
->middleware(array_filter([
'guest:'.config('fortify.guard'),
$limiter ? 'throttle:'.$limiter : null,
]))->name('login.store');
Route::post(RoutePath::for('logout', '/logout'), [AuthenticatedSessionController::class, 'destroy'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('logout');
// Password Reset...
if (Features::enabled(Features::resetPasswords())) {
if ($enableViews) {
Route::get(RoutePath::for('password.request', '/forgot-password'), [PasswordResetLinkController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('password.request');
Route::get(RoutePath::for('password.reset', '/reset-password/{token}'), [NewPasswordController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('password.reset');
}
Route::post(RoutePath::for('password.email', '/forgot-password'), [PasswordResetLinkController::class, 'store'])
->middleware(['guest:'.config('fortify.guard')])
->name('password.email');
Route::post(RoutePath::for('password.update', '/reset-password'), [NewPasswordController::class, 'store'])
->middleware(['guest:'.config('fortify.guard')])
->name('password.update');
}
// Registration...
if (Features::enabled(Features::registration())) {
if ($enableViews) {
Route::get(RoutePath::for('register', '/register'), [RegisteredUserController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('register');
}
Route::post(RoutePath::for('register', '/register'), [RegisteredUserController::class, 'store'])
->middleware(['guest:'.config('fortify.guard')])
->name('register.store');
}
// Email Verification...
if (Features::enabled(Features::emailVerification())) {
if ($enableViews) {
Route::get(RoutePath::for('verification.notice', '/email/verify'), [EmailVerificationPromptController::class, '__invoke'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('verification.notice');
}
Route::get(RoutePath::for('verification.verify', '/email/verify/{id}/{hash}'), [VerifyEmailController::class, '__invoke'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'signed', 'throttle:'.$verificationLimiter])
->name('verification.verify');
Route::post(RoutePath::for('verification.send', '/email/verification-notification'), [EmailVerificationNotificationController::class, 'store'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'throttle:'.$verificationLimiter])
->name('verification.send');
}
// Profile Information...
if (Features::enabled(Features::updateProfileInformation())) {
Route::put(RoutePath::for('user-profile-information.update', '/user/profile-information'), [ProfileInformationController::class, 'update'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('user-profile-information.update');
}
// Passwords...
if (Features::enabled(Features::updatePasswords())) {
Route::put(RoutePath::for('user-password.update', '/user/password'), [PasswordController::class, 'update'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('user-password.update');
}
// Password Confirmation...
if ($enableViews) {
Route::get(RoutePath::for('password.confirm', '/user/confirm-password'), [ConfirmablePasswordController::class, 'show'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('password.confirm');
}
Route::get(RoutePath::for('password.confirmation', '/user/confirmed-password-status'), [ConfirmedPasswordStatusController::class, 'show'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('password.confirmation');
Route::post(RoutePath::for('password.confirm', '/user/confirm-password'), [ConfirmablePasswordController::class, 'store'])
->middleware([config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')])
->name('password.confirm.store');
// Two Factor Authentication...
if (Features::enabled(Features::twoFactorAuthentication())) {
if ($enableViews) {
Route::get(RoutePath::for('two-factor.login', '/two-factor-challenge'), [TwoFactorAuthenticatedSessionController::class, 'create'])
->middleware(['guest:'.config('fortify.guard')])
->name('two-factor.login');
}
Route::post(RoutePath::for('two-factor.login', '/two-factor-challenge'), [TwoFactorAuthenticatedSessionController::class, 'store'])
->middleware(array_filter([
'guest:'.config('fortify.guard'),
$twoFactorLimiter ? 'throttle:'.$twoFactorLimiter : null,
]))->name('two-factor.login.store');
$twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword')
? [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard'), 'password.confirm']
: [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')];
Route::post(RoutePath::for('two-factor.enable', '/user/two-factor-authentication'), [TwoFactorAuthenticationController::class, 'store'])
->middleware($twoFactorMiddleware)
->name('two-factor.enable');
Route::post(RoutePath::for('two-factor.confirm', '/user/confirmed-two-factor-authentication'), [ConfirmedTwoFactorAuthenticationController::class, 'store'])
->middleware($twoFactorMiddleware)
->name('two-factor.confirm');
Route::delete(RoutePath::for('two-factor.disable', '/user/two-factor-authentication'), [TwoFactorAuthenticationController::class, 'destroy'])
->middleware($twoFactorMiddleware)
->name('two-factor.disable');
Route::get(RoutePath::for('two-factor.qr-code', '/user/two-factor-qr-code'), [TwoFactorQrCodeController::class, 'show'])
->middleware($twoFactorMiddleware)
->name('two-factor.qr-code');
Route::get(RoutePath::for('two-factor.secret-key', '/user/two-factor-secret-key'), [TwoFactorSecretKeyController::class, 'show'])
->middleware($twoFactorMiddleware)
->name('two-factor.secret-key');
Route::get(RoutePath::for('two-factor.recovery-codes', '/user/two-factor-recovery-codes'), [RecoveryCodeController::class, 'index'])
->middleware($twoFactorMiddleware)
->name('two-factor.recovery-codes');
Route::post(RoutePath::for('two-factor.recovery-codes', '/user/two-factor-recovery-codes'), [RecoveryCodeController::class, 'store'])
->middleware($twoFactorMiddleware)
->name('two-factor.regenerate-recovery-codes');
}
// Passkeys...
if (Features::enabled(Features::passkeys())) {
$throttle = $passkeyLimiter ? ['throttle:'.$passkeyLimiter] : [];
$passkeyAuthMiddleware = [config('fortify.auth_middleware', 'auth').':'.config('fortify.guard')];
$passkeyMiddleware = config('fortify-options.passkeys.confirmPassword', true)
? [...$passkeyAuthMiddleware, 'password.confirm']
: $passkeyAuthMiddleware;
$passkeyGuestMiddleware = ['guest:'.config('fortify.guard'), ...$throttle];
$passkeyConfirmMiddleware = [...$passkeyAuthMiddleware, ...$throttle];
$passkeyManageMiddleware = [...$passkeyMiddleware, ...$throttle];
Route::get(RoutePath::for('passkey.login-options', '/passkeys/login/options'), [PasskeyLoginController::class, 'index'])
->middleware($passkeyGuestMiddleware)
->name('passkey.login-options');
Route::post(RoutePath::for('passkey.login', '/passkeys/login'), [PasskeyLoginController::class, 'store'])
->middleware($passkeyGuestMiddleware)
->name('passkey.login');
Route::get(RoutePath::for('passkey.confirm-options', '/passkeys/confirm/options'), [PasskeyConfirmationController::class, 'index'])
->middleware($passkeyConfirmMiddleware)
->name('passkey.confirm-options');
Route::post(RoutePath::for('passkey.confirm', '/passkeys/confirm'), [PasskeyConfirmationController::class, 'store'])
->middleware($passkeyConfirmMiddleware)
->name('passkey.confirm');
Route::get(RoutePath::for('passkey.registration-options', '/user/passkeys/options'), [PasskeyRegistrationController::class, 'index'])
->middleware($passkeyManageMiddleware)
->name('passkey.registration-options');
Route::post(RoutePath::for('passkey.store', '/user/passkeys'), [PasskeyRegistrationController::class, 'store'])
->middleware($passkeyManageMiddleware)
->name('passkey.store');
Route::delete(RoutePath::for('passkey.destroy', '/user/passkeys/{passkey}'), [PasskeyRegistrationController::class, 'destroy'])
->middleware($passkeyMiddleware)
->name('passkey.destroy');
}
});

View file

@ -0,0 +1,119 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Auth\Events\Failed;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\LoginRateLimiter;
class AttemptToAuthenticate
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* The login rate limiter instance.
*
* @var \Laravel\Fortify\LoginRateLimiter
*/
protected $limiter;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param \Laravel\Fortify\LoginRateLimiter $limiter
* @return void
*/
public function __construct(StatefulGuard $guard, LoginRateLimiter $limiter)
{
$this->guard = $guard;
$this->limiter = $limiter;
}
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*
* @throws ValidationException
*/
public function handle($request, $next)
{
if (Fortify::$authenticateUsingCallback) {
return $this->handleUsingCustomCallback($request, $next);
}
if ($this->guard->attempt(
$request->only(Fortify::username(), 'password'),
$request->boolean('remember'))
) {
return $next($request);
}
$this->throwFailedAuthenticationException($request);
}
/**
* Attempt to authenticate using a custom callback.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*
* @throws ValidationException
*/
protected function handleUsingCustomCallback($request, $next)
{
$user = call_user_func(Fortify::$authenticateUsingCallback, $request);
if (! $user) {
$this->fireFailedEvent($request);
return $this->throwFailedAuthenticationException($request);
}
$this->guard->login($user, $request->boolean('remember'));
return $next($request);
}
/**
* Throw a failed authentication validation exception.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedAuthenticationException($request)
{
$this->limiter->increment($request);
throw ValidationException::withMessages([
Fortify::username() => [trans('auth.failed')],
]);
}
/**
* Fire the failed authentication attempt event with the given arguments.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function fireFailedEvent($request)
{
event(new Failed($this->guard?->name ?? config('fortify.guard'), null, [
Fortify::username() => $request->{Fortify::username()},
'password' => $request->password,
]));
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Support\Str;
use Laravel\Fortify\Fortify;
class CanonicalizeUsername
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle($request, $next)
{
if ($request->has(Fortify::username())) {
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
}
return $next($request);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Support\Str;
class CompletePasswordReset
{
/**
* Complete the password reset process for the given user.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param mixed $user
* @return void
*/
public function __invoke(StatefulGuard $guard, $user)
{
$user->setRememberToken(Str::random(60));
$user->save();
event(new PasswordReset($user));
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Contracts\Auth\StatefulGuard;
use Laravel\Fortify\Fortify;
class ConfirmPassword
{
/**
* Confirm that the given password is valid for the given user.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param mixed $user
* @param string|null $password
* @return bool
*/
public function __invoke(StatefulGuard $guard, $user, ?string $password = null)
{
$username = Fortify::username();
return is_null(Fortify::$confirmPasswordsUsingCallback) ? $guard->validate([
$username => $user->{$username},
'password' => $password,
]) : $this->confirmPasswordUsingCustomCallback($user, $password);
}
/**
* Confirm the user's password using a custom callback.
*
* @param mixed $user
* @param string|null $password
* @return bool
*/
protected function confirmPasswordUsingCustomCallback($user, ?string $password = null)
{
return call_user_func(
Fortify::$confirmPasswordsUsingCallback,
$user,
$password
);
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider;
use Laravel\Fortify\Events\TwoFactorAuthenticationConfirmed;
use Laravel\Fortify\Fortify;
class ConfirmTwoFactorAuthentication
{
/**
* The two factor authentication provider.
*
* @var \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider
*/
protected $provider;
/**
* Create a new action instance.
*
* @param \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider $provider
* @return void
*/
public function __construct(TwoFactorAuthenticationProvider $provider)
{
$this->provider = $provider;
}
/**
* Confirm the two factor authentication configuration for the user.
*
* @param mixed $user
* @param string $code
* @return void
*
* @throws ValidationException
*/
public function __invoke($user, $code)
{
if (empty($user->two_factor_secret) ||
empty($code) ||
! $this->provider->verify(Fortify::currentEncrypter()->decrypt($user->two_factor_secret), $code)) {
throw ValidationException::withMessages([
'code' => [__('The provided two factor authentication code was invalid.')],
])->errorBag('confirmTwoFactorAuthentication');
}
$user->forceFill([
'two_factor_confirmed_at' => now(),
])->save();
TwoFactorAuthenticationConfirmed::dispatch($user);
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Laravel\Fortify\Actions;
use Laravel\Fortify\Events\TwoFactorAuthenticationDisabled;
use Laravel\Fortify\Fortify;
class DisableTwoFactorAuthentication
{
/**
* Disable two factor authentication for the user.
*
* @param mixed $user
* @return void
*/
public function __invoke($user)
{
if (! is_null($user->two_factor_secret) ||
! is_null($user->two_factor_recovery_codes) ||
! is_null($user->two_factor_confirmed_at)) {
$user->forceFill([
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
] + (Fortify::confirmsTwoFactorAuthentication() || ! is_null($user->two_factor_confirmed_at) ? [
'two_factor_confirmed_at' => null,
] : []))->save();
TwoFactorAuthenticationDisabled::dispatch($user);
}
}
}

View file

@ -0,0 +1,53 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Support\Collection;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider;
use Laravel\Fortify\Events\TwoFactorAuthenticationEnabled;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\RecoveryCode;
class EnableTwoFactorAuthentication
{
/**
* The two factor authentication provider.
*
* @var \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider
*/
protected $provider;
/**
* Create a new action instance.
*
* @param \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider $provider
* @return void
*/
public function __construct(TwoFactorAuthenticationProvider $provider)
{
$this->provider = $provider;
}
/**
* Enable two factor authentication for the user.
*
* @param mixed $user
* @param bool $force
* @return void
*/
public function __invoke($user, $force = false)
{
if (empty($user->two_factor_secret) || $force === true) {
$secretLength = (int) config('fortify-options.two-factor-authentication.secret-length', 16);
$user->forceFill([
'two_factor_secret' => Fortify::currentEncrypter()->encrypt($this->provider->generateSecretKey($secretLength)),
'two_factor_recovery_codes' => Fortify::currentEncrypter()->encrypt(json_encode(Collection::times(8, function () {
return RecoveryCode::generate();
})->all())),
])->save();
TwoFactorAuthenticationEnabled::dispatch($user);
}
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Auth\Events\Lockout;
use Laravel\Fortify\Contracts\LockoutResponse;
use Laravel\Fortify\LoginRateLimiter;
class EnsureLoginIsNotThrottled
{
/**
* The login rate limiter instance.
*
* @var \Laravel\Fortify\LoginRateLimiter
*/
protected $limiter;
/**
* Create a new class instance.
*
* @param \Laravel\Fortify\LoginRateLimiter $limiter
* @return void
*/
public function __construct(LoginRateLimiter $limiter)
{
$this->limiter = $limiter;
}
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle($request, $next)
{
if (! $this->limiter->tooManyAttempts($request)) {
return $next($request);
}
event(new Lockout($request));
return app(LockoutResponse::class);
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Support\Collection;
use Laravel\Fortify\Events\RecoveryCodesGenerated;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\RecoveryCode;
class GenerateNewRecoveryCodes
{
/**
* Generate new recovery codes for the user.
*
* @param mixed $user
* @return void
*/
public function __invoke($user)
{
$user->forceFill([
'two_factor_recovery_codes' => Fortify::currentEncrypter()->encrypt(json_encode(Collection::times(8, function () {
return RecoveryCode::generate();
})->all())),
])->save();
RecoveryCodesGenerated::dispatch($user);
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Laravel\Fortify\Actions;
use Laravel\Fortify\LoginRateLimiter;
class PrepareAuthenticatedSession
{
/**
* The login rate limiter instance.
*
* @var \Laravel\Fortify\LoginRateLimiter
*/
protected $limiter;
/**
* Create a new class instance.
*
* @param \Laravel\Fortify\LoginRateLimiter $limiter
* @return void
*/
public function __construct(LoginRateLimiter $limiter)
{
$this->limiter = $limiter;
}
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle($request, $next)
{
if ($request->hasSession()) {
$request->session()->regenerate();
}
$this->limiter->clear($request);
return $next($request);
}
}

View file

@ -0,0 +1,160 @@
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Auth\Events\Failed;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Support\Timebox;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\RedirectsIfTwoFactorAuthenticatable;
use Laravel\Fortify\Events\TwoFactorAuthenticationChallenged;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\LoginRateLimiter;
use Laravel\Fortify\TwoFactorAuthenticatable;
class RedirectIfTwoFactorAuthenticatable implements RedirectsIfTwoFactorAuthenticatable
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* The login rate limiter instance.
*
* @var \Laravel\Fortify\LoginRateLimiter
*/
protected $limiter;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param \Laravel\Fortify\LoginRateLimiter $limiter
* @return void
*/
public function __construct(StatefulGuard $guard, LoginRateLimiter $limiter)
{
$this->guard = $guard;
$this->limiter = $limiter;
}
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle($request, $next)
{
$user = $this->validateCredentials($request);
if (Fortify::confirmsTwoFactorAuthentication()) {
if (optional($user)->two_factor_secret &&
! is_null(optional($user)->two_factor_confirmed_at) &&
in_array(TwoFactorAuthenticatable::class, class_uses_recursive($user))) {
return $this->twoFactorChallengeResponse($request, $user);
} else {
return $next($request);
}
}
if (optional($user)->two_factor_secret &&
in_array(TwoFactorAuthenticatable::class, class_uses_recursive($user))) {
return $this->twoFactorChallengeResponse($request, $user);
}
return $next($request);
}
/**
* Attempt to validate the incoming credentials.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
protected function validateCredentials($request)
{
if (Fortify::$authenticateUsingCallback) {
return tap(call_user_func(Fortify::$authenticateUsingCallback, $request), function ($user) use ($request) {
if (! $user) {
$this->fireFailedEvent($request);
$this->throwFailedAuthenticationException($request);
}
});
}
$provider = $this->guard->getProvider();
return (new Timebox())->call(function () use ($request, $provider) {
return tap($provider->retrieveByCredentials($request->only(Fortify::username(), 'password')), function ($user) use ($provider, $request) {
if (! $user || ! $provider->validateCredentials($user, ['password' => $request->password])) {
$this->fireFailedEvent($request, $user);
$this->throwFailedAuthenticationException($request);
}
if (config('hashing.rehash_on_login', true) && method_exists($provider, 'rehashPasswordIfRequired')) {
$provider->rehashPasswordIfRequired($user, ['password' => $request->password]);
}
});
}, 200000);
}
/**
* Throw a failed authentication validation exception.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedAuthenticationException($request)
{
$this->limiter->increment($request);
throw ValidationException::withMessages([
Fortify::username() => [trans('auth.failed')],
]);
}
/**
* Fire the failed authentication attempt event with the given arguments.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @return void
*/
protected function fireFailedEvent($request, $user = null)
{
event(new Failed($this->guard?->name ?? config('fortify.guard'), $user, [
Fortify::username() => $request->{Fortify::username()},
'password' => $request->password,
]));
}
/**
* Get the two factor authentication enabled response.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function twoFactorChallengeResponse($request, $user)
{
$request->session()->put([
'login.id' => $user->getKey(),
'login.remember' => $request->boolean('remember'),
]);
TwoFactorAuthenticationChallenged::dispatch($user);
return $request->wantsJson()
? response()->json(['two_factor' => true])
: redirect()->route('two-factor.login');
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace Laravel\Fortify\Console;
use Illuminate\Console\Command;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\FortifyServiceProvider;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'fortify:install')]
class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fortify:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install all of the Fortify resources';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->callSilent('vendor:publish', [
'--provider' => FortifyServiceProvider::class,
]);
$this->registerFortifyServiceProvider();
$this->components->info('Fortify scaffolding installed successfully.');
}
/**
* Register the Fortify service provider in the application configuration file.
*/
protected function registerFortifyServiceProvider(): void
{
if (! method_exists(ServiceProvider::class, 'addProviderToBootstrapFile')) {
return;
}
ServiceProvider::addProviderToBootstrapFile(\App\Providers\FortifyServiceProvider::class);
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface ConfirmPasswordViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,14 @@
<?php
namespace Laravel\Fortify\Contracts;
interface CreatesNewUsers
{
/**
* Validate and create a newly registered user.
*
* @param array $input
* @return \Illuminate\Foundation\Auth\User
*/
public function create(array $input);
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface EmailVerificationNotificationSentResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface FailedPasswordConfirmationResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface FailedPasswordResetLinkRequestResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface FailedPasswordResetResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface FailedTwoFactorLoginResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LockoutResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LoginResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LoginViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface LogoutResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Laravel\Passkeys\Contracts\PasskeyUser as BasePasskeyUser;
interface PasskeyUser extends BasePasskeyUser
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface PasswordConfirmedResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface PasswordResetResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface PasswordUpdateResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface ProfileInformationUpdatedResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface RecoveryCodesGeneratedResponse extends Responsable
{
//
}

View file

@ -0,0 +1,15 @@
<?php
namespace Laravel\Fortify\Contracts;
interface RedirectsIfTwoFactorAuthenticatable
{
/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle($request, $next);
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface RegisterResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface RegisterViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface RequestPasswordResetLinkViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface ResetPasswordViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,11 @@
<?php
namespace Laravel\Fortify\Contracts;
/**
* @method void reset(\Illuminate\Foundation\Auth\User $user, array $input)
*/
interface ResetsUserPasswords
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface SuccessfulPasswordResetLinkRequestResponse extends Responsable
{
//
}

View file

@ -0,0 +1,32 @@
<?php
namespace Laravel\Fortify\Contracts;
interface TwoFactorAuthenticationProvider
{
/**
* Generate a new secret key.
*
* @return string
*/
public function generateSecretKey();
/**
* Get the two factor authentication QR code URL.
*
* @param string $companyName
* @param string $companyEmail
* @param string $secret
* @return string
*/
public function qrCodeUrl($companyName, $companyEmail, $secret);
/**
* Verify the given token.
*
* @param string $secret
* @param string $code
* @return bool
*/
public function verify($secret, $code);
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface TwoFactorChallengeViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface TwoFactorConfirmedResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface TwoFactorDisabledResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface TwoFactorEnabledResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface TwoFactorLoginResponse extends Responsable
{
//
}

View file

@ -0,0 +1,11 @@
<?php
namespace Laravel\Fortify\Contracts;
/**
* @method void update(\Illuminate\Foundation\Auth\User $user, array $input)
*/
interface UpdatesUserPasswords
{
//
}

View file

@ -0,0 +1,11 @@
<?php
namespace Laravel\Fortify\Contracts;
/**
* @method void update(\Illuminate\Foundation\Auth\User $user, array $input)
*/
interface UpdatesUserProfileInformation
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface VerifyEmailResponse extends Responsable
{
//
}

View file

@ -0,0 +1,10 @@
<?php
namespace Laravel\Fortify\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface VerifyEmailViewResponse extends Responsable
{
//
}

View file

@ -0,0 +1,28 @@
<?php
namespace Laravel\Fortify\Events;
use Illuminate\Foundation\Events\Dispatchable;
class PasswordUpdatedViaController
{
use Dispatchable;
/**
* The user instance.
*
* @var \App\Models\User
*/
public $user;
/**
* Create a new event instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}

View file

@ -0,0 +1,38 @@
<?php
namespace Laravel\Fortify\Events;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class RecoveryCodeReplaced
{
use Dispatchable, SerializesModels;
/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;
/**
* The recovery code.
*
* @var string
*/
public $code;
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param string $code
* @return void
*/
public function __construct($user, $code)
{
$this->user = $user;
$this->code = $code;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace Laravel\Fortify\Events;
use Illuminate\Foundation\Events\Dispatchable;
class RecoveryCodesGenerated
{
use Dispatchable;
/**
* The user instance.
*
* @var \App\Models\User
*/
public $user;
/**
* Create a new event instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace Laravel\Fortify\Events;
class TwoFactorAuthenticationChallenged extends TwoFactorAuthenticationEvent
{
//
}

View file

@ -0,0 +1,8 @@
<?php
namespace Laravel\Fortify\Events;
class TwoFactorAuthenticationConfirmed extends TwoFactorAuthenticationEvent
{
//
}

View file

@ -0,0 +1,8 @@
<?php
namespace Laravel\Fortify\Events;
class TwoFactorAuthenticationDisabled extends TwoFactorAuthenticationEvent
{
//
}

View file

@ -0,0 +1,8 @@
<?php
namespace Laravel\Fortify\Events;
class TwoFactorAuthenticationEnabled extends TwoFactorAuthenticationEvent
{
//
}

View file

@ -0,0 +1,28 @@
<?php
namespace Laravel\Fortify\Events;
use Illuminate\Foundation\Events\Dispatchable;
abstract class TwoFactorAuthenticationEvent
{
use Dispatchable;
/**
* The user instance.
*
* @var \App\Models\User
*/
public $user;
/**
* Create a new event instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace Laravel\Fortify\Events;
class TwoFactorAuthenticationFailed extends TwoFactorAuthenticationEvent
{
//
}

View file

@ -0,0 +1,8 @@
<?php
namespace Laravel\Fortify\Events;
class ValidTwoFactorAuthenticationCodeProvided extends TwoFactorAuthenticationEvent
{
//
}

175
vendor/laravel/fortify/src/Features.php vendored Normal file
View file

@ -0,0 +1,175 @@
<?php
namespace Laravel\Fortify;
class Features
{
/**
* Determine if the given feature is enabled.
*
* @param string $feature
* @return bool
*/
public static function enabled(string $feature)
{
return in_array($feature, config('fortify.features', []));
}
/**
* Determine if the feature is enabled and has a given option enabled.
*
* @param string $feature
* @param string $option
* @return bool
*/
public static function optionEnabled(string $feature, string $option)
{
return static::enabled($feature) &&
config("fortify-options.{$feature}.{$option}") === true;
}
/**
* Determine if the application is using any features that require "profile" management.
*
* @return bool
*/
public static function hasProfileFeatures()
{
return static::enabled(static::updateProfileInformation()) ||
static::enabled(static::updatePasswords()) ||
static::enabled(static::twoFactorAuthentication()) ||
static::enabled(static::passkeys());
}
/**
* Determine if the application can update a user's profile information.
*
* @return bool
*/
public static function canUpdateProfileInformation()
{
return static::enabled(static::updateProfileInformation());
}
/**
* Determine if the application is using any security profile features.
*
* @return bool
*/
public static function hasSecurityFeatures()
{
return static::enabled(static::updatePasswords()) ||
static::canManageTwoFactorAuthentication() ||
static::canManagePasskeys();
}
/**
* Determine if the application can update user passwords.
*
* @return bool
*/
public static function canUpdatePasswords()
{
return static::enabled(static::updatePasswords());
}
/**
* Determine if the application can manage two factor authentication.
*
* @return bool
*/
public static function canManageTwoFactorAuthentication()
{
return static::enabled(static::twoFactorAuthentication());
}
/**
* Determine if the application can manage passkeys.
*
* @return bool
*/
public static function canManagePasskeys()
{
return static::enabled(static::passkeys());
}
/**
* Enable the registration feature.
*
* @return string
*/
public static function registration()
{
return 'registration';
}
/**
* Enable the password reset feature.
*
* @return string
*/
public static function resetPasswords()
{
return 'reset-passwords';
}
/**
* Enable the email verification feature.
*
* @return string
*/
public static function emailVerification()
{
return 'email-verification';
}
/**
* Enable the update profile information feature.
*
* @return string
*/
public static function updateProfileInformation()
{
return 'update-profile-information';
}
/**
* Enable the update password feature.
*
* @return string
*/
public static function updatePasswords()
{
return 'update-passwords';
}
/**
* Enable the two factor authentication feature.
*
* @param array $options
* @return string
*/
public static function twoFactorAuthentication(array $options = [])
{
if (! empty($options)) {
config(['fortify-options.two-factor-authentication' => $options]);
}
return 'two-factor-authentication';
}
/**
* Enable the passkeys feature.
*
* @param array $options
* @return string
*/
public static function passkeys(array $options = [])
{
if (! empty($options)) {
config(['fortify-options.passkeys' => $options]);
}
return 'passkeys';
}
}

378
vendor/laravel/fortify/src/Fortify.php vendored Normal file
View file

@ -0,0 +1,378 @@
<?php
namespace Laravel\Fortify;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Contracts\RedirectsIfTwoFactorAuthenticatable;
use Laravel\Fortify\Contracts\RegisterViewResponse;
use Laravel\Fortify\Contracts\RequestPasswordResetLinkViewResponse;
use Laravel\Fortify\Contracts\ResetPasswordViewResponse;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
use Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;
use Laravel\Fortify\Http\Responses\SimpleViewResponse;
class Fortify
{
/**
* The callback that is responsible for building the authentication pipeline array, if applicable.
*
* @var callable|null
*/
public static $authenticateThroughCallback;
/**
* The callback that is responsible for validating authentication credentials, if applicable.
*
* @var callable|null
*/
public static $authenticateUsingCallback;
/**
* The callback that is responsible for confirming user passwords.
*
* @var callable|null
*/
public static $confirmPasswordsUsingCallback;
/**
* The callback that is responsible for generating recovery codes.
*
* @var callable|null
*/
public static $recoveryCodeGenerator;
/**
* Indicates if Fortify routes will be registered.
*
* @var bool
*/
public static $registersRoutes = true;
/**
* The encrypter instance that is used to encrypt attributes.
*
* @var \Illuminate\Contracts\Encryption\Encrypter|null
*/
public static $encrypter;
const PASSWORD_UPDATED = 'password-updated';
const PROFILE_INFORMATION_UPDATED = 'profile-information-updated';
const RECOVERY_CODES_GENERATED = 'recovery-codes-generated';
const TWO_FACTOR_AUTHENTICATION_CONFIRMED = 'two-factor-authentication-confirmed';
const TWO_FACTOR_AUTHENTICATION_DISABLED = 'two-factor-authentication-disabled';
const TWO_FACTOR_AUTHENTICATION_ENABLED = 'two-factor-authentication-enabled';
const VERIFICATION_LINK_SENT = 'verification-link-sent';
/**
* Get the username used for authentication.
*
* @return string
*/
public static function username()
{
return config('fortify.username', 'email');
}
/**
* Get the name of the email address request variable / field.
*
* @return string
*/
public static function email()
{
return config('fortify.email', 'email');
}
/**
* Get a completion redirect path for a specific feature.
*
* @param string $redirect
* @return string
*/
public static function redirects(string $redirect, $default = null)
{
return config('fortify.redirects.'.$redirect) ?? $default ?? config('fortify.home');
}
/**
* Register the views for Fortify using conventional names under the given namespace.
*
* @param string $namespace
* @return void
*/
public static function viewNamespace(string $namespace)
{
static::viewPrefix($namespace.'::');
}
/**
* Register the views for Fortify using conventional names under the given prefix.
*
* @param string $prefix
* @return void
*/
public static function viewPrefix(string $prefix)
{
static::loginView($prefix.'login');
static::twoFactorChallengeView($prefix.'two-factor-challenge');
static::registerView($prefix.'register');
static::requestPasswordResetLinkView($prefix.'forgot-password');
static::resetPasswordView($prefix.'reset-password');
static::verifyEmailView($prefix.'verify-email');
static::confirmPasswordView($prefix.'confirm-password');
}
/**
* Specify which view should be used as the login view.
*
* @param callable|string $view
* @return void
*/
public static function loginView($view)
{
app()->singleton(LoginViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Specify which view should be used as the two factor authentication challenge view.
*
* @param callable|string $view
* @return void
*/
public static function twoFactorChallengeView($view)
{
app()->singleton(TwoFactorChallengeViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Specify which view should be used as the new password view.
*
* @param callable|string $view
* @return void
*/
public static function resetPasswordView($view)
{
app()->singleton(ResetPasswordViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Specify which view should be used as the registration view.
*
* @param callable|string $view
* @return void
*/
public static function registerView($view)
{
app()->singleton(RegisterViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Specify which view should be used as the email verification prompt.
*
* @param callable|string $view
* @return void
*/
public static function verifyEmailView($view)
{
app()->singleton(VerifyEmailViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Specify which view should be used as the password confirmation prompt.
*
* @param callable|string $view
* @return void
*/
public static function confirmPasswordView($view)
{
app()->singleton(ConfirmPasswordViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Specify which view should be used as the request password reset link view.
*
* @param callable|string $view
* @return void
*/
public static function requestPasswordResetLinkView($view)
{
app()->singleton(RequestPasswordResetLinkViewResponse::class, function () use ($view) {
return new SimpleViewResponse($view);
});
}
/**
* Register a callback that is responsible for building the authentication pipeline array.
*
* @param callable $callback
* @return void
*/
public static function loginThrough(callable $callback)
{
static::authenticateThrough($callback);
}
/**
* Register a callback that is responsible for building the authentication pipeline array.
*
* @param callable $callback
* @return void
*/
public static function authenticateThrough(callable $callback)
{
static::$authenticateThroughCallback = $callback;
}
/**
* Register a callback that is responsible for validating incoming authentication credentials.
*
* @param callable $callback
* @return void
*/
public static function authenticateUsing(callable $callback)
{
static::$authenticateUsingCallback = $callback;
}
/**
* Register a class / callback that should be used to redirect users for two factor authentication.
*
* @param callable|string $callback
* @return void
*/
public static function redirectUserForTwoFactorAuthenticationUsing($callback)
{
app()->scoped(RedirectsIfTwoFactorAuthenticatable::class, $callback);
}
/**
* Register a callback that is responsible for confirming existing user passwords as valid.
*
* @param callable $callback
* @return void
*/
public static function confirmPasswordsUsing(callable $callback)
{
static::$confirmPasswordsUsingCallback = $callback;
}
/**
* Register a class / callback that should be used to create new users.
*
* @param callable|string $callback
* @return void
*/
public static function createUsersUsing($callback)
{
app()->singleton(CreatesNewUsers::class, $callback);
}
/**
* Register a class / callback that should be used to update user profile information.
*
* @param callable|string $callback
* @return void
*/
public static function updateUserProfileInformationUsing($callback)
{
app()->singleton(UpdatesUserProfileInformation::class, $callback);
}
/**
* Register a class / callback that should be used to update user passwords.
*
* @param callable|string $callback
* @return void
*/
public static function updateUserPasswordsUsing($callback)
{
app()->singleton(UpdatesUserPasswords::class, $callback);
}
/**
* Register a class / callback that should be used to reset user passwords.
*
* @param callable|string $callback
* @return void
*/
public static function resetUserPasswordsUsing($callback)
{
app()->singleton(ResetsUserPasswords::class, $callback);
}
/**
* Register a callback that should be used to generate recovery codes.
*
* @param callable $callback
* @return void
*/
public static function generateRecoveryCodesUsing(callable $callback)
{
static::$recoveryCodeGenerator = $callback;
}
/**
* Determine if Fortify is confirming two factor authentication configurations.
*
* @return bool
*/
public static function confirmsTwoFactorAuthentication()
{
return Features::enabled(Features::twoFactorAuthentication()) &&
Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm');
}
/**
* Set the encrypter instance that will be used to encrypt attributes.
*
* @param \Illuminate\Contracts\Encryption\Encrypter|null $encrypter
* @return static
*/
public static function encryptUsing($encrypter)
{
static::$encrypter = $encrypter;
return new static;
}
/**
* Get the current encrypter being used by the model.
*
* @return \Illuminate\Contracts\Encryption\Encrypter
*/
public static function currentEncrypter()
{
return static::$encrypter ?? Model::$encrypter ?? Crypt::getFacadeRoot();
}
/**
* Configure Fortify to not register its routes.
*
* @return static
*/
public static function ignoreRoutes()
{
static::$registersRoutes = false;
return new static;
}
}

View file

@ -0,0 +1,244 @@
<?php
namespace Laravel\Fortify;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Actions\RedirectIfTwoFactorAuthenticatable;
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse as EmailVerificationNotificationSentResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse as FailedPasswordConfirmationResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse as FailedPasswordResetLinkRequestResponseContract;
use Laravel\Fortify\Contracts\FailedPasswordResetResponse as FailedPasswordResetResponseContract;
use Laravel\Fortify\Contracts\FailedTwoFactorLoginResponse as FailedTwoFactorLoginResponseContract;
use Laravel\Fortify\Contracts\LockoutResponse as LockoutResponseContract;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Laravel\Fortify\Contracts\LogoutResponse as LogoutResponseContract;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract;
use Laravel\Fortify\Contracts\PasswordResetResponse as PasswordResetResponseContract;
use Laravel\Fortify\Contracts\PasswordUpdateResponse as PasswordUpdateResponseContract;
use Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse as ProfileInformationUpdatedResponseContract;
use Laravel\Fortify\Contracts\RecoveryCodesGeneratedResponse as RecoveryCodesGeneratedResponseContract;
use Laravel\Fortify\Contracts\RedirectsIfTwoFactorAuthenticatable as RedirectsIfTwoFactorAuthenticatableContract;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse as SuccessfulPasswordResetLinkRequestResponseContract;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider as TwoFactorAuthenticationProviderContract;
use Laravel\Fortify\Contracts\TwoFactorConfirmedResponse as TwoFactorConfirmedResponseContract;
use Laravel\Fortify\Contracts\TwoFactorDisabledResponse as TwoFactorDisabledResponseContract;
use Laravel\Fortify\Contracts\TwoFactorEnabledResponse as TwoFactorEnabledResponseContract;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;
use Laravel\Fortify\Contracts\VerifyEmailResponse as VerifyEmailResponseContract;
use Laravel\Fortify\Http\Responses\EmailVerificationNotificationSentResponse;
use Laravel\Fortify\Http\Responses\FailedPasswordConfirmationResponse;
use Laravel\Fortify\Http\Responses\FailedPasswordResetLinkRequestResponse;
use Laravel\Fortify\Http\Responses\FailedPasswordResetResponse;
use Laravel\Fortify\Http\Responses\FailedTwoFactorLoginResponse;
use Laravel\Fortify\Http\Responses\LockoutResponse;
use Laravel\Fortify\Http\Responses\LoginResponse;
use Laravel\Fortify\Http\Responses\LogoutResponse;
use Laravel\Fortify\Http\Responses\PasswordConfirmedResponse;
use Laravel\Fortify\Http\Responses\PasswordResetResponse;
use Laravel\Fortify\Http\Responses\PasswordUpdateResponse;
use Laravel\Fortify\Http\Responses\ProfileInformationUpdatedResponse;
use Laravel\Fortify\Http\Responses\RecoveryCodesGeneratedResponse;
use Laravel\Fortify\Http\Responses\RegisterResponse;
use Laravel\Fortify\Http\Responses\SuccessfulPasswordResetLinkRequestResponse;
use Laravel\Fortify\Http\Responses\TwoFactorConfirmedResponse;
use Laravel\Fortify\Http\Responses\TwoFactorDisabledResponse;
use Laravel\Fortify\Http\Responses\TwoFactorEnabledResponse;
use Laravel\Fortify\Http\Responses\TwoFactorLoginResponse;
use Laravel\Fortify\Http\Responses\VerifyEmailResponse;
use Laravel\Passkeys\Passkeys as LaravelPasskeys;
use PragmaRX\Google2FA\Google2FA;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/fortify.php', 'fortify');
$this->configurePasskeys();
$this->registerResponseBindings();
$this->app->singleton(TwoFactorAuthenticationProviderContract::class, function ($app) {
return new TwoFactorAuthenticationProvider(
$app->make(Google2FA::class),
$app->make(Repository::class)
);
});
$this->app->scoped(RedirectsIfTwoFactorAuthenticatableContract::class, function ($app) {
return $app->make(RedirectIfTwoFactorAuthenticatable::class);
});
$this->app->bind(StatefulGuard::class, function () {
return Auth::guard(config('fortify.guard', null));
});
}
/**
* Register the response bindings.
*
* @return void
*/
protected function registerResponseBindings()
{
$this->app->singleton(FailedPasswordConfirmationResponseContract::class, FailedPasswordConfirmationResponse::class);
$this->app->singleton(FailedPasswordResetLinkRequestResponseContract::class, FailedPasswordResetLinkRequestResponse::class);
$this->app->singleton(FailedPasswordResetResponseContract::class, FailedPasswordResetResponse::class);
$this->app->singleton(FailedTwoFactorLoginResponseContract::class, FailedTwoFactorLoginResponse::class);
$this->app->singleton(LockoutResponseContract::class, LockoutResponse::class);
$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
$this->app->singleton(LogoutResponseContract::class, LogoutResponse::class);
$this->app->singleton(PasswordConfirmedResponseContract::class, PasswordConfirmedResponse::class);
$this->app->singleton(PasswordResetResponseContract::class, PasswordResetResponse::class);
$this->app->singleton(PasswordUpdateResponseContract::class, PasswordUpdateResponse::class);
$this->app->singleton(ProfileInformationUpdatedResponseContract::class, ProfileInformationUpdatedResponse::class);
$this->app->singleton(RecoveryCodesGeneratedResponseContract::class, RecoveryCodesGeneratedResponse::class);
$this->app->singleton(RegisterResponseContract::class, RegisterResponse::class);
$this->app->singleton(EmailVerificationNotificationSentResponseContract::class, EmailVerificationNotificationSentResponse::class);
$this->app->singleton(SuccessfulPasswordResetLinkRequestResponseContract::class, SuccessfulPasswordResetLinkRequestResponse::class);
$this->app->singleton(TwoFactorConfirmedResponseContract::class, TwoFactorConfirmedResponse::class);
$this->app->singleton(TwoFactorDisabledResponseContract::class, TwoFactorDisabledResponse::class);
$this->app->singleton(TwoFactorEnabledResponseContract::class, TwoFactorEnabledResponse::class);
$this->app->singleton(TwoFactorLoginResponseContract::class, TwoFactorLoginResponse::class);
$this->app->singleton(VerifyEmailResponseContract::class, VerifyEmailResponse::class);
}
/**
* Configure passkeys integration.
*
* @return void
*/
protected function configurePasskeys()
{
LaravelPasskeys::ignoreRoutes();
if ($model = $this->passkeyUserModel()) {
LaravelPasskeys::useUserModel($model);
}
config([
'passkeys.relying_party_id' => config('fortify.passkeys.relying_party_id', parse_url(config('app.url'), PHP_URL_HOST)),
'passkeys.allowed_origins' => config('fortify.passkeys.allowed_origins', [config('app.url')]),
'passkeys.user_handle_secret' => config('fortify.passkeys.user_handle_secret', config('app.key')),
'passkeys.timeout' => config('fortify.passkeys.timeout', 60000),
'passkeys.guard' => config('fortify.guard', 'web'),
'passkeys.middleware' => config('fortify.middleware', ['web']),
'passkeys.management_middleware' => config('fortify-options.passkeys.confirmPassword', true)
? ['password.confirm']
: [],
'passkeys.redirect' => Fortify::redirects('login'),
'passkeys.throttle' => $this->passkeyThrottleMiddleware(),
]);
}
/**
* Get the authentication model used by Fortify's guard.
*
* @return string|null
*/
protected function passkeyUserModel()
{
$guard = config('fortify.guard', config('auth.defaults.guard', 'web'));
$provider = config("auth.guards.{$guard}.provider", config('auth.defaults.provider'));
if (! $provider) {
return config('auth.providers.users.model');
}
return config("auth.providers.{$provider}.model", config('auth.providers.users.model'));
}
/**
* Get the passkeys throttle middleware.
*
* @return string|null
*/
protected function passkeyThrottleMiddleware()
{
$limiter = config('fortify.limiters.passkeys');
return $limiter ? 'throttle:'.$limiter : null;
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->configurePublishing();
$this->configureRoutes();
$this->registerCommands();
}
/**
* Configure the publishable resources offered by the package.
*
* @return void
*/
protected function configurePublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../stubs/fortify.php' => config_path('fortify.php'),
], 'fortify-config');
$this->publishes([
__DIR__.'/../stubs/CreateNewUser.php' => app_path('Actions/Fortify/CreateNewUser.php'),
__DIR__.'/../stubs/FortifyServiceProvider.php' => app_path('Providers/FortifyServiceProvider.php'),
__DIR__.'/../stubs/PasswordValidationRules.php' => app_path('Actions/Fortify/PasswordValidationRules.php'),
__DIR__.'/../stubs/ResetUserPassword.php' => app_path('Actions/Fortify/ResetUserPassword.php'),
__DIR__.'/../stubs/UpdateUserProfileInformation.php' => app_path('Actions/Fortify/UpdateUserProfileInformation.php'),
__DIR__.'/../stubs/UpdateUserPassword.php' => app_path('Actions/Fortify/UpdateUserPassword.php'),
], 'fortify-support');
$method = method_exists($this, 'publishesMigrations') ? 'publishesMigrations' : 'publishes';
$this->{$method}([
__DIR__.'/../database/migrations' => database_path('migrations'),
LaravelPasskeys::migrationPath() => database_path('migrations'),
], 'fortify-migrations');
}
}
/**
* Configure the routes offered by the application.
*
* @return void
*/
protected function configureRoutes()
{
if (Fortify::$registersRoutes) {
Route::group([
'namespace' => 'Laravel\Fortify\Http\Controllers',
'domain' => config('fortify.domain', null),
'prefix' => config('fortify.prefix'),
], function () {
$this->loadRoutesFrom(__DIR__.'/../routes/routes.php');
});
}
}
/**
* Register the package's commands.
*/
protected function registerCommands(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
Console\InstallCommand::class,
]);
}
}
}

View file

@ -0,0 +1,111 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Routing\Pipeline;
use Laravel\Fortify\Actions\AttemptToAuthenticate;
use Laravel\Fortify\Actions\CanonicalizeUsername;
use Laravel\Fortify\Actions\EnsureLoginIsNotThrottled;
use Laravel\Fortify\Actions\PrepareAuthenticatedSession;
use Laravel\Fortify\Contracts\LoginResponse;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Contracts\LogoutResponse;
use Laravel\Fortify\Contracts\RedirectsIfTwoFactorAuthenticatable;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Requests\LoginRequest;
class AuthenticatedSessionController extends Controller
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @return void
*/
public function __construct(StatefulGuard $guard)
{
$this->guard = $guard;
}
/**
* Show the login view.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\LoginViewResponse
*/
public function create(Request $request): LoginViewResponse
{
return app(LoginViewResponse::class);
}
/**
* Attempt to authenticate a new session.
*
* @param \Laravel\Fortify\Http\Requests\LoginRequest $request
* @return mixed
*/
public function store(LoginRequest $request)
{
return $this->loginPipeline($request)->then(function ($request) {
return app(LoginResponse::class);
});
}
/**
* Get the authentication pipeline instance.
*
* @param \Laravel\Fortify\Http\Requests\LoginRequest $request
* @return \Illuminate\Pipeline\Pipeline
*/
protected function loginPipeline(LoginRequest $request)
{
if (Fortify::$authenticateThroughCallback) {
return (new Pipeline(app()))->send($request)->through(array_filter(
call_user_func(Fortify::$authenticateThroughCallback, $request)
));
}
if (is_array(config('fortify.pipelines.login'))) {
return (new Pipeline(app()))->send($request)->through(array_filter(
config('fortify.pipelines.login')
));
}
return (new Pipeline(app()))->send($request)->through(array_filter([
config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,
config('fortify.lowercase_usernames') ? CanonicalizeUsername::class : null,
Features::enabled(Features::twoFactorAuthentication()) ? RedirectsIfTwoFactorAuthenticatable::class : null,
AttemptToAuthenticate::class,
PrepareAuthenticatedSession::class,
]));
}
/**
* Destroy an authenticated session.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\LogoutResponse
*/
public function destroy(Request $request): LogoutResponse
{
$this->guard->logout();
if ($request->hasSession()) {
$request->session()->invalidate();
$request->session()->regenerateToken();
}
return app(LogoutResponse::class);
}
}

View file

@ -0,0 +1,65 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Date;
use Laravel\Fortify\Actions\ConfirmPassword;
use Laravel\Fortify\Contracts\ConfirmPasswordViewResponse;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse;
class ConfirmablePasswordController extends Controller
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @return void
*/
public function __construct(StatefulGuard $guard)
{
$this->guard = $guard;
}
/**
* Show the confirm password view.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\ConfirmPasswordViewResponse
*/
public function show(Request $request)
{
return app(ConfirmPasswordViewResponse::class);
}
/**
* Confirm the user's password.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Support\Responsable
*/
public function store(Request $request)
{
$confirmed = app(ConfirmPassword::class)(
$this->guard, $request->user(), $request->input('password')
);
if ($confirmed) {
$request->session()->put('auth.password_confirmed_at', Date::now()->unix());
}
return $confirmed
? app(PasswordConfirmedResponse::class)
: app(FailedPasswordConfirmationResponse::class);
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Date;
class ConfirmedPasswordStatusController extends Controller
{
/**
* Get the password confirmation status.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function show(Request $request)
{
$lastConfirmation = $request->session()->get(
'auth.password_confirmed_at', 0
);
$lastConfirmed = (Date::now()->unix() - $lastConfirmation);
$confirmed = $lastConfirmed < $request->input(
'seconds', config('auth.password_timeout', 900)
);
return response()->json([
'confirmed' => $confirmed,
], headers: array_filter([
'X-Retry-After' => $confirmed ? $lastConfirmed : null,
]));
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication;
use Laravel\Fortify\Contracts\TwoFactorConfirmedResponse;
class ConfirmedTwoFactorAuthenticationController extends Controller
{
/**
* Enable two factor authentication for the user.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication $confirm
* @return \Laravel\Fortify\Contracts\TwoFactorConfirmedResponse
*/
public function store(Request $request, ConfirmTwoFactorAuthentication $confirm)
{
$confirm($request->user(), $request->input('code'));
return app(TwoFactorConfirmedResponse::class);
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse;
use Laravel\Fortify\Http\Responses\RedirectAsIntended;
class EmailVerificationNotificationController extends Controller
{
/**
* Send a new email verification notification.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function store(Request $request)
{
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new JsonResponse('', 204)
: app(RedirectAsIntended::class, ['name' => 'email-verification']);
}
$request->user()->sendEmailVerificationNotification();
return app(EmailVerificationNotificationSentResponse::class);
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;
use Laravel\Fortify\Http\Responses\RedirectAsIntended;
class EmailVerificationPromptController extends Controller
{
/**
* Display the email verification prompt.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\VerifyEmailViewResponse
*/
public function __invoke(Request $request)
{
return $request->user()->hasVerifiedEmail()
? app(RedirectAsIntended::class, ['name' => 'email-verification'])
: app(VerifyEmailViewResponse::class);
}
}

View file

@ -0,0 +1,99 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Laravel\Fortify\Actions\CompletePasswordReset;
use Laravel\Fortify\Contracts\FailedPasswordResetResponse;
use Laravel\Fortify\Contracts\PasswordResetResponse;
use Laravel\Fortify\Contracts\ResetPasswordViewResponse;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
use Laravel\Fortify\Fortify;
class NewPasswordController extends Controller
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @return void
*/
public function __construct(StatefulGuard $guard)
{
$this->guard = $guard;
}
/**
* Show the new password view.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\ResetPasswordViewResponse
*/
public function create(Request $request): ResetPasswordViewResponse
{
return app(ResetPasswordViewResponse::class);
}
/**
* Reset the user's password.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Support\Responsable
*/
public function store(Request $request): Responsable
{
if (config('fortify.lowercase_usernames') && $request->has(Fortify::email())) {
$request->merge([
Fortify::email() => Str::lower($request->{Fortify::email()}),
]);
}
$request->validate([
'token' => 'required',
Fortify::email() => 'required|email',
'password' => 'required',
]);
// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$status = $this->broker()->reset(
$request->only(Fortify::email(), 'password', 'password_confirmation', 'token'),
function ($user) use ($request) {
app(ResetsUserPasswords::class)->reset($user, $request->all());
app(CompletePasswordReset::class)($this->guard, $user);
}
);
// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
return $status == Password::PASSWORD_RESET
? app(PasswordResetResponse::class, ['status' => $status])
: app(FailedPasswordResetResponse::class, ['status' => $status]);
}
/**
* Get the broker to be used during password reset.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
protected function broker(): PasswordBroker
{
return Password::broker(config('fortify.passwords'));
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Password;
use Laravel\Fortify\Contracts\PasswordUpdateResponse;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
use Laravel\Fortify\Events\PasswordUpdatedViaController;
class PasswordController extends Controller
{
/**
* Update the user's password.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Contracts\UpdatesUserPasswords $updater
* @return \Laravel\Fortify\Contracts\PasswordUpdateResponse
*/
public function update(Request $request, UpdatesUserPasswords $updater)
{
$updater->update($request->user(), $request->all());
$this->broker()->deleteToken($request->user());
event(new PasswordUpdatedViaController($request->user()));
return app(PasswordUpdateResponse::class);
}
/**
* Get the broker to be used to delete any existing password reset tokens.
*
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
protected function broker(): PasswordBroker
{
return Password::broker(config('fortify.passwords'));
}
}

View file

@ -0,0 +1,57 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;
use Laravel\Fortify\Contracts\RequestPasswordResetLinkViewResponse;
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Requests\SendPasswordResetLinkRequest;
class PasswordResetLinkController extends Controller
{
/**
* Show the reset password link request view.
*/
public function create(Request $request): RequestPasswordResetLinkViewResponse
{
return app(RequestPasswordResetLinkViewResponse::class);
}
/**
* Send a reset link to the given user.
*/
public function store(SendPasswordResetLinkRequest $request): Responsable
{
if (config('fortify.lowercase_usernames') && $request->has(Fortify::email())) {
$request->merge([
Fortify::email() => Str::lower($request->{Fortify::email()}),
]);
}
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$status = $this->broker()->sendResetLink(
$request->only(Fortify::email())
);
return $status == Password::RESET_LINK_SENT
? app(SuccessfulPasswordResetLinkRequestResponse::class, ['status' => $status])
: app(FailedPasswordResetLinkRequestResponse::class, ['status' => $status]);
}
/**
* Get the broker to be used during password reset.
*/
protected function broker(): PasswordBroker
{
return Password::broker(config('fortify.passwords'));
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
use Laravel\Fortify\Fortify;
class ProfileInformationController extends Controller
{
/**
* Update the user's profile information.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Contracts\UpdatesUserProfileInformation $updater
* @return \Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse
*/
public function update(Request $request,
UpdatesUserProfileInformation $updater)
{
if (config('fortify.lowercase_usernames') && $request->has(Fortify::username())) {
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
}
$updater->update($request->user(), $request->all());
return app(ProfileInformationUpdatedResponse::class);
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Actions\GenerateNewRecoveryCodes;
use Laravel\Fortify\Contracts\RecoveryCodesGeneratedResponse;
use Laravel\Fortify\Fortify;
class RecoveryCodeController extends Controller
{
/**
* Get the two factor authentication recovery codes for authenticated user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse|array
*/
public function index(Request $request)
{
if (! $request->user()->two_factor_secret ||
! $request->user()->two_factor_recovery_codes) {
return [];
}
return response()->json(json_decode(Fortify::currentEncrypter()->decrypt(
$request->user()->two_factor_recovery_codes
), true));
}
/**
* Generate a fresh set of two factor authentication recovery codes.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Actions\GenerateNewRecoveryCodes $generate
* @return \Laravel\Fortify\Contracts\RecoveryCodesGeneratedResponse
*/
public function store(Request $request, GenerateNewRecoveryCodes $generate)
{
$generate($request->user());
return app(RecoveryCodesGeneratedResponse::class);
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Laravel\Fortify\Contracts\RegisterResponse;
use Laravel\Fortify\Contracts\RegisterViewResponse;
use Laravel\Fortify\Fortify;
class RegisteredUserController extends Controller
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @return void
*/
public function __construct(StatefulGuard $guard)
{
$this->guard = $guard;
}
/**
* Show the registration view.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Fortify\Contracts\RegisterViewResponse
*/
public function create(Request $request): RegisterViewResponse
{
return app(RegisterViewResponse::class);
}
/**
* Create a new registered user.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Contracts\CreatesNewUsers $creator
* @return \Laravel\Fortify\Contracts\RegisterResponse
*/
public function store(Request $request,
CreatesNewUsers $creator): RegisterResponse
{
if (config('fortify.lowercase_usernames') && $request->has(Fortify::username())) {
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
}
event(new Registered($user = $creator->create($request->all())));
$this->guard->login($user, $request->boolean('remember'));
if ($request->hasSession()) {
$request->session()->regenerate();
}
return app(RegisterResponse::class);
}
}

View file

@ -0,0 +1,76 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\FailedTwoFactorLoginResponse;
use Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse;
use Laravel\Fortify\Events\TwoFactorAuthenticationFailed;
use Laravel\Fortify\Events\ValidTwoFactorAuthenticationCodeProvided;
use Laravel\Fortify\Http\Requests\TwoFactorLoginRequest;
class TwoFactorAuthenticatedSessionController extends Controller
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected $guard;
/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @return void
*/
public function __construct(StatefulGuard $guard)
{
$this->guard = $guard;
}
/**
* Show the two factor authentication challenge view.
*
* @param \Laravel\Fortify\Http\Requests\TwoFactorLoginRequest $request
* @return \Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse
*/
public function create(TwoFactorLoginRequest $request): TwoFactorChallengeViewResponse
{
if (! $request->hasChallengedUser()) {
throw new HttpResponseException(redirect()->route('login'));
}
return app(TwoFactorChallengeViewResponse::class);
}
/**
* Attempt to authenticate a new session using the two factor authentication code.
*
* @param \Laravel\Fortify\Http\Requests\TwoFactorLoginRequest $request
* @return mixed
*/
public function store(TwoFactorLoginRequest $request)
{
$user = $request->challengedUser();
if ($code = $request->validRecoveryCode()) {
$user->replaceRecoveryCode($code);
} elseif (! $request->hasValidCode()) {
event(new TwoFactorAuthenticationFailed($user));
return app(FailedTwoFactorLoginResponse::class)->toResponse($request);
}
event(new ValidTwoFactorAuthenticationCodeProvided($user));
$this->guard->login($user, $request->remember());
$request->session()->regenerate();
return app(TwoFactorLoginResponse::class);
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Actions\DisableTwoFactorAuthentication;
use Laravel\Fortify\Actions\EnableTwoFactorAuthentication;
use Laravel\Fortify\Contracts\TwoFactorDisabledResponse;
use Laravel\Fortify\Contracts\TwoFactorEnabledResponse;
use Laravel\Fortify\Fortify;
class TwoFactorAuthenticationController extends Controller
{
/**
* Enable two factor authentication for the user.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Actions\EnableTwoFactorAuthentication $enable
* @return \Laravel\Fortify\Contracts\TwoFactorEnabledResponse
*/
public function store(Request $request, EnableTwoFactorAuthentication $enable)
{
$user = $request->user();
$enable($user, $request->boolean('force', false));
if (Fortify::confirmsTwoFactorAuthentication() &&
! is_null($user->two_factor_secret) &&
is_null($user->two_factor_confirmed_at)) {
$request->session()->remove('two_factor_confirming_at');
}
return app(TwoFactorEnabledResponse::class);
}
/**
* Disable two factor authentication for the user.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Actions\DisableTwoFactorAuthentication $disable
* @return \Laravel\Fortify\Contracts\TwoFactorDisabledResponse
*/
public function destroy(Request $request, DisableTwoFactorAuthentication $disable)
{
$disable($request->user());
return app(TwoFactorDisabledResponse::class);
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class TwoFactorQrCodeController extends Controller
{
/**
* Get the SVG element for the user's two factor authentication QR code.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse|array
*/
public function show(Request $request)
{
if (is_null($request->user()->two_factor_secret)) {
return [];
}
return response()->json([
'svg' => $request->user()->twoFactorQrCodeSvg(),
'url' => $request->user()->twoFactorQrCodeUrl(),
]);
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Fortify;
class TwoFactorSecretKeyController extends Controller
{
/**
* Get the current user's two factor authentication setup / secret key.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function show(Request $request)
{
if (is_null($request->user()->two_factor_secret)) {
abort(404, 'Two factor authentication has not been enabled.');
}
return response()->json([
'secretKey' => Fortify::currentEncrypter()->decrypt($request->user()->two_factor_secret),
]);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Laravel\Fortify\Http\Controllers;
use Illuminate\Auth\Events\Verified;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\VerifyEmailResponse;
use Laravel\Fortify\Http\Requests\VerifyEmailRequest;
class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*
* @param \Laravel\Fortify\Http\Requests\VerifyEmailRequest $request
* @return \Laravel\Fortify\Contracts\VerifyEmailResponse
*/
public function __invoke(VerifyEmailRequest $request)
{
if ($request->user()->hasVerifiedEmail()) {
return app(VerifyEmailResponse::class);
}
if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
return app(VerifyEmailResponse::class);
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Laravel\Fortify\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Fortify\Fortify;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
Fortify::username() => 'required|string',
'password' => 'required|string',
'remember' => 'sometimes',
];
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Laravel\Fortify\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Fortify\Fortify;
class SendPasswordResetLinkRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
Fortify::email() => 'required|email',
];
}
}

View file

@ -0,0 +1,140 @@
<?php
namespace Laravel\Fortify\Http\Requests;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Laravel\Fortify\Contracts\FailedTwoFactorLoginResponse;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider;
use Laravel\Fortify\Fortify;
class TwoFactorLoginRequest extends FormRequest
{
/**
* The user attempting the two factor challenge.
*
* @var mixed
*/
protected $challengedUser;
/**
* Indicates if the user wished to be remembered after login.
*
* @var bool
*/
protected $remember;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'code' => 'nullable|string',
'recovery_code' => 'nullable|string',
];
}
/**
* Determine if the request has a valid two factor code.
*
* @return bool
*/
public function hasValidCode()
{
return $this->code && tap(app(TwoFactorAuthenticationProvider::class)->verify(
Fortify::currentEncrypter()->decrypt($this->challengedUser()->two_factor_secret), $this->code
), function ($result) {
if ($result) {
$this->session()->forget('login.id');
}
});
}
/**
* Get the valid recovery code if one exists on the request.
*
* @return string|null
*/
public function validRecoveryCode()
{
if (! $this->recovery_code) {
return;
}
return tap(collect($this->challengedUser()->recoveryCodes())->first(function ($code) {
return hash_equals($code, $this->recovery_code) ? $code : null;
}), function ($code) {
if ($code) {
$this->session()->forget('login.id');
}
});
}
/**
* Determine if there is a challenged user in the current session.
*
* @return bool
*/
public function hasChallengedUser()
{
if ($this->challengedUser) {
return true;
}
$model = app(StatefulGuard::class)->getProvider()->getModel();
return $this->session()->has('login.id') &&
$model::find($this->session()->get('login.id'));
}
/**
* Get the user that is attempting the two factor challenge.
*
* @return mixed
*/
public function challengedUser()
{
if ($this->challengedUser) {
return $this->challengedUser;
}
$model = app(StatefulGuard::class)->getProvider()->getModel();
if (! $this->session()->has('login.id') ||
! $user = $model::find($this->session()->get('login.id'))) {
throw new HttpResponseException(
app(FailedTwoFactorLoginResponse::class)->toResponse($this)
);
}
return $this->challengedUser = $user;
}
/**
* Determine if the user wanted to be remembered after login.
*
* @return bool
*/
public function remember()
{
if (! $this->remember) {
$this->remember = $this->session()->pull('login.remember', false);
}
return $this->remember;
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Laravel\Fortify\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class VerifyEmailRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
if (! hash_equals((string) $this->user()->getKey(), (string) $this->route('id'))) {
return false;
}
if (! hash_equals(sha1($this->user()->getEmailForVerification()), (string) $this->route('hash'))) {
return false;
}
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [];
}
/**
* Determine if fields not present in rules should fail validation.
*
* @return bool
*/
protected function shouldFailOnUnknownFields(): bool
{
return false;
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse as EmailVerificationNotificationSentResponseContract;
use Laravel\Fortify\Fortify;
class EmailVerificationNotificationSentResponse implements EmailVerificationNotificationSentResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 202)
: back()->with('status', Fortify::VERIFICATION_LINK_SENT);
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse as FailedPasswordConfirmationResponseContract;
class FailedPasswordConfirmationResponse implements FailedPasswordConfirmationResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
public function toResponse($request)
{
$message = __('The provided password was incorrect.');
if ($request->wantsJson()) {
throw ValidationException::withMessages([
'password' => [$message],
]);
}
return back()->withErrors(['password' => $message]);
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse as FailedPasswordResetLinkRequestResponseContract;
class FailedPasswordResetLinkRequestResponse implements FailedPasswordResetLinkRequestResponseContract
{
/**
* The response status language key.
*
* @var string
*/
protected $status;
/**
* Create a new response instance.
*
* @param string $status
* @return void
*/
public function __construct(string $status)
{
$this->status = $status;
}
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
public function toResponse($request)
{
if ($request->wantsJson()) {
throw ValidationException::withMessages([
'email' => [trans($this->status)],
]);
}
return back()
->withInput($request->only('email'))
->withErrors(['email' => trans($this->status)]);
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\FailedPasswordResetResponse as FailedPasswordResetResponseContract;
class FailedPasswordResetResponse implements FailedPasswordResetResponseContract
{
/**
* The response status language key.
*
* @var string
*/
protected $status;
/**
* Create a new response instance.
*
* @param string $status
* @return void
*/
public function __construct(string $status)
{
$this->status = $status;
}
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
public function toResponse($request)
{
if ($request->wantsJson()) {
throw ValidationException::withMessages([
'email' => [trans($this->status)],
]);
}
return back()
->withInput($request->only('email'))
->withErrors(['email' => trans($this->status)]);
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\FailedTwoFactorLoginResponse as FailedTwoFactorLoginResponseContract;
class FailedTwoFactorLoginResponse implements FailedTwoFactorLoginResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
public function toResponse($request)
{
[$key, $message] = $request->filled('recovery_code')
? ['recovery_code', __('The provided two factor recovery code was invalid.')]
: ['code', __('The provided two factor authentication code was invalid.')];
if ($request->wantsJson()) {
throw ValidationException::withMessages([
$key => [$message],
]);
}
return redirect()->route('two-factor.login')->withErrors([$key => $message]);
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\LockoutResponse as LockoutResponseContract;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\LoginRateLimiter;
class LockoutResponse implements LockoutResponseContract
{
/**
* The login rate limiter instance.
*
* @var \Laravel\Fortify\LoginRateLimiter
*/
protected $limiter;
/**
* Create a new response instance.
*
* @param \Laravel\Fortify\LoginRateLimiter $limiter
* @return void
*/
public function __construct(LoginRateLimiter $limiter)
{
$this->limiter = $limiter;
}
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Illuminate\Validation\ValidationException
*/
public function toResponse($request)
{
return with($this->limiter->availableIn($request), function ($seconds) {
throw ValidationException::withMessages([
Fortify::username() => [
trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
],
])->status(429);
});
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Laravel\Fortify\Fortify;
class LoginResponse implements LoginResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? response()->json(['two_factor' => false])
: redirect()->intended(Fortify::redirects('login'));
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\LogoutResponse as LogoutResponseContract;
use Laravel\Fortify\Fortify;
class LogoutResponse implements LogoutResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 204)
: redirect(Fortify::redirects('logout', '/'));
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract;
use Laravel\Fortify\Fortify;
class PasswordConfirmedResponse implements PasswordConfirmedResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 201)
: redirect()->intended(Fortify::redirects('password-confirmation'));
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\PasswordResetResponse as PasswordResetResponseContract;
use Laravel\Fortify\Fortify;
class PasswordResetResponse implements PasswordResetResponseContract
{
/**
* The response status language key.
*
* @var string
*/
protected $status;
/**
* Create a new response instance.
*
* @param string $status
* @return void
*/
public function __construct(string $status)
{
$this->status = $status;
}
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse(['message' => trans($this->status)], 200)
: redirect(Fortify::redirects('password-reset', config('fortify.views', true) ? route('login') : null))->with('status', trans($this->status));
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\PasswordUpdateResponse as PasswordUpdateResponseContract;
use Laravel\Fortify\Fortify;
class PasswordUpdateResponse implements PasswordUpdateResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::PASSWORD_UPDATED);
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse as ProfileInformationUpdatedResponseContract;
use Laravel\Fortify\Fortify;
class ProfileInformationUpdatedResponse implements ProfileInformationUpdatedResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::PROFILE_INFORMATION_UPDATED);
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Laravel\Fortify\Http\Responses;
use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\RecoveryCodesGeneratedResponse as RecoveryCodesGeneratedResponseContract;
use Laravel\Fortify\Fortify;
class RecoveryCodesGeneratedResponse implements RecoveryCodesGeneratedResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::RECOVERY_CODES_GENERATED);
}
}

Some files were not shown because too many files have changed in this diff Show more