2018-09-16 05:15:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Auth;
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class TwoFactorAuth
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
if($request->user()) {
|
|
|
|
$user = $request->user();
|
|
|
|
$enabled = (bool) $user->{'2fa_enabled'};
|
|
|
|
if($enabled != false) {
|
|
|
|
$checkpoint = 'i/auth/checkpoint';
|
2020-07-10 04:32:45 +00:00
|
|
|
if($request->session()->has('2fa.session.active') !== true && !$request->is($checkpoint) && !$request->is('logout'))
|
2018-09-16 05:15:45 +00:00
|
|
|
{
|
|
|
|
return redirect('/i/auth/checkpoint');
|
2019-10-07 09:25:26 +00:00
|
|
|
} elseif($request->session()->has('2fa.attempts') && (int) $request->session()->get('2fa.attempts') > 3) {
|
2018-10-26 01:49:35 +00:00
|
|
|
$request->session()->pull('2fa.attempts');
|
|
|
|
Auth::logout();
|
2018-09-16 05:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|