Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Apr 8, 2024
1 parent 5f21610 commit b69accb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!'));
Expand Down
1 change: 1 addition & 0 deletions src/Http/Controllers/Auth/TwoFactorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
5 changes: 4 additions & 1 deletion src/Http/Middleware/TwoFactorAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
5 changes: 4 additions & 1 deletion src/Interfaces/TwoFactorAuthenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

interface TwoFactorAuthenticatable
{
//
/**
* Determine whether the object requires two factor authentitaction.
*/
public function requiresTwoFactorAuthentication(): bool;
}
2 changes: 1 addition & 1 deletion src/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Root
*
* @var string
*/
public const VERSION = '2.2.12';
public const VERSION = '2.2.13';

/**
* The registered booting callbacks.
Expand Down

0 comments on commit b69accb

Please sign in to comment.