mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup in 2FA middleware.
This commit is contained in:
parent
95648c37b3
commit
55f13ef121
@ -23,34 +23,49 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Middleware;
|
namespace FireflyIII\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
|
||||||
use Auth;
|
|
||||||
use Session;
|
|
||||||
/**
|
/**
|
||||||
* Class AuthenticateTwoFactor.
|
* Class AuthenticateTwoFactor.
|
||||||
*/
|
*/
|
||||||
class AuthenticateTwoFactor
|
class AuthenticateTwoFactor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* The authentication factory instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @var \Illuminate\Contracts\Auth\Factory
|
||||||
* @param \Closure $next
|
|
||||||
* @param string|null $guard
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next, $guard = null)
|
protected $auth;
|
||||||
{
|
|
||||||
if (Auth::guard($guard)->guest()) {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new middleware instance.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Auth $auth)
|
||||||
|
{
|
||||||
|
$this->auth = $auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $request
|
||||||
|
* @param Closure $next
|
||||||
|
* @param array ...$guards
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|mixed
|
||||||
|
* @throws \Illuminate\Container\EntryNotFoundException
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next, ...$guards)
|
||||||
|
{
|
||||||
|
if ($this->auth->guest()) {
|
||||||
return redirect()->guest('login');
|
return redirect()->guest('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', false)->data;
|
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
|
||||||
$has2faSecret = null !== Preferences::get('twoFactorAuthSecret');
|
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
|
||||||
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');
|
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');
|
||||||
|
|
||||||
if ($is2faEnabled && $has2faSecret && !$is2faAuthed) {
|
if ($is2faEnabled && $has2faSecret && !$is2faAuthed) {
|
||||||
@ -61,4 +76,5 @@ class AuthenticateTwoFactor
|
|||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user