Add DangerZone middleware

This commit is contained in:
Daniel Supernault 2018-09-09 14:19:57 -06:00
parent 7c1b0c2065
commit 90fbf8e481
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 33 additions and 0 deletions

View file

@ -57,6 +57,7 @@ class Kernel extends HttpKernel
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'dangerzone' => \App\Http\Middleware\DangerZone::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

View file

@ -0,0 +1,32 @@
<?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(!Auth::check()) {
return redirect(route('login'));
}
if(!$request->is('i/auth/sudo')) {
if( false == $request->cookie('sudoMode') ) {
return redirect('/i/auth/sudo')->withCookie('redirectNext', $request->url());
}
if( $request->cookie('sudoMode') < Carbon::now()->subMinutes(30)->timestamp ) {
return redirect('/i/auth/sudo')->withCookie('redirectNext', $request->url());
}
}
return $next($request);
}
}