diff --git a/src/Http/Controllers/Auth/LoginController.php b/src/Http/Controllers/Auth/LoginController.php index 8ed2f2ca..36570b4d 100644 --- a/src/Http/Controllers/Auth/LoginController.php +++ b/src/Http/Controllers/Auth/LoginController.php @@ -62,7 +62,10 @@ public function login(Request $request): RedirectResponse new Login(Auth::getDefaultDriver(), $request->user(), $request->filled('remember')) ); - if ($request->user() instanceof TwoFactorAuthenticatable && $request->user()->can('viewRoot')) { + if ($request->user()->can('viewRoot') + && $request->user() instanceof TwoFactorAuthenticatable + && $request->user()->requiresTwoFactorAuthentication() + ) { $request->user()->notify(new TwoFactorLink()); $request->session()->flash('status', __('The two factor authentication link has been sent!')); diff --git a/src/Http/Controllers/Auth/TwoFactorController.php b/src/Http/Controllers/Auth/TwoFactorController.php index 9296095e..fe4f235f 100644 --- a/src/Http/Controllers/Auth/TwoFactorController.php +++ b/src/Http/Controllers/Auth/TwoFactorController.php @@ -25,6 +25,7 @@ public function __construct() $this->middleware('throttle:6,1')->only(['resend']); $this->middleware(static function (Request $request, Closure $next): BaseResponse { if (! $request->user() instanceof TwoFactorAuthenticatable + || ! $request->user()->requiresTwoFactorAuthentication() || $request->session()->has('root.auth.two-factor') ) { return ResponseFactory::redirectToIntended(URL::route('root.dashboard')); diff --git a/src/Http/Middleware/TwoFactorAuthenticate.php b/src/Http/Middleware/TwoFactorAuthenticate.php index 24e5ceee..20c5232f 100644 --- a/src/Http/Middleware/TwoFactorAuthenticate.php +++ b/src/Http/Middleware/TwoFactorAuthenticate.php @@ -17,7 +17,10 @@ class TwoFactorAuthenticate */ public function handle(Request $request, Closure $next): Response { - if ($request->user() instanceof TwoFactorAuthenticatable && ! $request->session()->has('root.auth.two-factor')) { + if ($request->user() instanceof TwoFactorAuthenticatable + && $request->user()->requiresTwoFactorAuthentication() + && ! $request->session()->has('root.auth.two-factor') + ) { return Redirect::route('root.auth.two-factor.show'); } diff --git a/src/Interfaces/TwoFactorAuthenticatable.php b/src/Interfaces/TwoFactorAuthenticatable.php index 5c5a4f08..a6a8cacc 100644 --- a/src/Interfaces/TwoFactorAuthenticatable.php +++ b/src/Interfaces/TwoFactorAuthenticatable.php @@ -4,5 +4,8 @@ interface TwoFactorAuthenticatable { - // + /** + * Determine whether the object requires two factor authentitaction. + */ + public function requiresTwoFactorAuthentication(): bool; } diff --git a/src/Root.php b/src/Root.php index 094443c2..6237ccd8 100644 --- a/src/Root.php +++ b/src/Root.php @@ -23,7 +23,7 @@ class Root * * @var string */ - public const VERSION = '2.2.12'; + public const VERSION = '2.2.13'; /** * The registered booting callbacks.