2016-09-06 11:24:25 +02:00
|
|
|
<?php namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Auth;
|
|
|
|
use Session;
|
|
|
|
|
|
|
|
// https://arjunphp.com/laravel5-inactivity-idle-session-logout/
|
|
|
|
class SessionDataCheckMiddleware {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check session data, if role is not valid logout the request
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-09-11 16:30:23 +02:00
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2016-09-06 11:24:25 +02:00
|
|
|
$bag = Session::getMetadataBag();
|
2016-09-11 16:30:23 +02:00
|
|
|
$max = env('IDLE_TIMEOUT_MINUTES', 6 * 60) * 60; // minute to second conversion
|
|
|
|
$elapsed = time() - $bag->getLastUsed();
|
2016-09-06 11:24:25 +02:00
|
|
|
|
2016-09-11 16:30:23 +02:00
|
|
|
if ( ! $bag || $elapsed > $max) {
|
|
|
|
$request->session()->flush();
|
|
|
|
Auth::logout();
|
|
|
|
$request->session()->flash('warning', trans('texts.inactive_logout'));
|
2016-09-06 11:24:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|