pixelfed/app/Http/Middleware/DangerZone.php

41 lines
1.2 KiB
PHP
Raw Normal View History

2018-09-09 20:19:57 +00:00
<?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)
{
2020-02-18 06:16:44 +00:00
if( $request->session()->get('sudoModeAttempts') > 3) {
$request->session()->pull('redirectNext');
$request->session()->pull('sudoModeAttempts');
Auth::logout();
return redirect(route('login'));
}
2018-09-09 20:19:57 +00:00
if(!Auth::check()) {
return redirect(route('login'));
}
2020-03-15 04:35:35 +00:00
if(!$request->is('i/auth/sudo') && $request->session()->get('sudoTrustDevice') != 1) {
if( !$request->session()->has('sudoMode') ) {
$request->session()->put('redirectNext', $request->url());
return redirect('/i/auth/sudo');
2018-09-09 20:19:57 +00:00
}
if( $request->session()->get('sudoMode') < Carbon::now()->subMinutes(30)->timestamp ) {
$request->session()->put('redirectNext', $request->url());
return redirect('/i/auth/sudo');
2018-09-09 20:19:57 +00:00
}
}
return $next($request);
}
}