1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Http/Middleware/DangerZone.php
2020-02-17 23:16:44 -07:00

40 lines
1.2 KiB
PHP

<?php
namespace App\Http\Middleware;
use App, Auth, Closure;
use Carbon\Carbon;
class DangerZone
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if( $request->session()->get('sudoModeAttempts') > 3) {
$request->session()->pull('redirectNext');
$request->session()->pull('sudoModeAttempts');
Auth::logout();
return redirect(route('login'));
}
if(!Auth::check()) {
return redirect(route('login'));
}
if(!$request->is('i/auth/sudo')) {
if( !$request->session()->has('sudoMode') ) {
$request->session()->put('redirectNext', $request->url());
return redirect('/i/auth/sudo');
}
if( $request->session()->get('sudoMode') < Carbon::now()->subMinutes(30)->timestamp ) {
$request->session()->put('redirectNext', $request->url());
return redirect('/i/auth/sudo');
}
}
return $next($request);
}
}