Skip to content

Commit

Permalink
Make pages configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 19, 2024
1 parent 256a55d commit eb370d8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 36 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ return [
];
```

If you want to fully customize the pages, you can override the classes in the `config/filament-two-factor-auth.php` file:

```php
return [
// ...

'login' => Login::class,
'challenge' => LoginTwoFactor::class,
'two_factor_settings' => TwoFactor::class,
'password_reset' => PasswordReset::class,
'password_confirmation' => PasswordConfirmation::class,
'request_password_reset' => RequestPasswordReset::class,
];
```

Make sure you extend the original classes from the package.


If you want to use the SMS method, you need to provide an SMS service. You can check the [Laravel Notifications documentation](https://laravel-notification-channels.com/about/) for ready-to-use services.

**Also make sure your user model has a `phone` attribute.**
Expand Down
22 changes: 22 additions & 0 deletions config/filament-two-factor-auth.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

use Vormkracht10\TwoFactorAuth\Enums\TwoFactorType;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\Login;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\LoginTwoFactor;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\PasswordConfirmation;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\PasswordReset;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\RequestPasswordReset;
use Vormkracht10\TwoFactorAuth\Pages\TwoFactor;

return [

Expand Down Expand Up @@ -32,4 +38,20 @@
|
*/
'sms_service' => null, // For example: MessageBird::class

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| If you want to customize the pages, you can override the used classes here.
| Make your that your classes extend the original classes.
|
*/
'login' => Login::class,
'challenge' => LoginTwoFactor::class,
'two_factor_settings' => TwoFactor::class,
'password_reset' => PasswordReset::class,
'password_confirmation' => PasswordConfirmation::class,
'request_password_reset' => RequestPasswordReset::class,
];
78 changes: 42 additions & 36 deletions src/TwoFactorAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@

namespace Vormkracht10\TwoFactorAuth;

use Filament\Support\Assets\AlpineComponent;
use Filament\Support\Assets\Asset;
use Filament\Support\Assets\Css;
use Livewire\Livewire;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Features;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Cache\RateLimiting\Limit;
use Filament\Support\Assets\Css;
use Filament\Support\Assets\Asset;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Responses\TwoFactorLoginResponse;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\Redirect;
use Filament\Support\Facades\FilamentIcon;
use Filament\Support\Facades\FilamentAsset;
use Illuminate\Support\Facades\RateLimiter;
use Filament\Support\Assets\AlpineComponent;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Vormkracht10\TwoFactorAuth\Commands\TwoFactorAuthCommand;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\Login;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\LoginTwoFactor;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\PasswordConfirmation;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\PasswordReset;
use Vormkracht10\TwoFactorAuth\Http\Livewire\Auth\RequestPasswordReset;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Laravel\Fortify\Http\Responses\TwoFactorLoginResponse;
use Vormkracht10\TwoFactorAuth\Testing\TestsTwoFactorAuth;
use Vormkracht10\TwoFactorAuth\Http\Responses\LoginResponse;
use Vormkracht10\TwoFactorAuth\Commands\TwoFactorAuthCommand;
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use Vormkracht10\TwoFactorAuth\Http\Responses\TwoFactorChallengeViewResponse;
use Vormkracht10\TwoFactorAuth\Pages\TwoFactor;
use Vormkracht10\TwoFactorAuth\Testing\TestsTwoFactorAuth;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;

class TwoFactorAuthServiceProvider extends PackageServiceProvider
{
Expand Down Expand Up @@ -143,7 +137,7 @@ public function packageBooted(): void
protected function forceFortifyConfig(): void
{
config([
'filament.auth.pages.login' => Login::class,
'filament.auth.pages.login' => config('filament-two-factor-auth.login'),
'fortify.views' => true,
'fortify.home' => config('filament.home_url'),
'forms.dark_mode' => config('filament.dark_mode'),
Expand All @@ -166,16 +160,16 @@ protected function defineRateLimiters(): void
protected function overrideFortifyViews(): void
{
Fortify::loginView(function () {
return app()->call(Login::class);
return app()->call(config('filament.auth.pages.login'));
});

if (Features::enabled(Features::resetPasswords())) {
Fortify::requestPasswordResetLinkView(function () {
return app()->call(RequestPasswordReset::class);
return app()->call(config('filament-two-factor-auth.request_password_reset'));
});

Fortify::resetPasswordView(function ($request) {
return app()->call(PasswordReset::class);
return app()->call(config('filament-two-factor-auth.password_reset'));
});
}

Expand All @@ -186,22 +180,34 @@ protected function overrideFortifyViews(): void
}

Fortify::confirmPasswordView(function () {
return app()->call(PasswordConfirmation::class);
return app()->call(config('filament-two-factor-auth.password_confirmation'));
});

if (Features::enabled(Features::twoFactorAuthentication())) {
Fortify::twoFactorChallengeView(function () {
return app()->call(LoginTwoFactor::class);
return app()->call(config('filament-two-factor-auth.challenge'));
});
}
}

protected function registerContractsAndComponents(): void
{
Livewire::component((new PasswordReset)->getName(), PasswordReset::class);
Livewire::component((new RequestPasswordReset)->getName(), RequestPasswordReset::class);
Livewire::component((new LoginTwoFactor)->getName(), LoginTwoFactor::class);
Livewire::component((new TwoFactor)->getName(), TwoFactor::class);
Livewire::component(
'password-reset',
config('filament-two-factor-auth.password_reset')
);
Livewire::component(
'request-password-reset',
config('filament-two-factor-auth.request_password_reset')
);
Livewire::component(
'login-two-factor',
config('filament-two-factor-auth.challenge')
);
Livewire::component(
'two-factor',
config('filament-two-factor-auth.two_factor_settings')
);

$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
$this->app->singleton(TwoFactorLoginResponseContract::class, TwoFactorLoginResponse::class);
Expand Down

0 comments on commit eb370d8

Please sign in to comment.