1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Http/Middleware/SessionDataCheckMiddleware.php

32 lines
852 B
PHP
Raw Normal View History

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);
}
}