43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Session\Store;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
use Session;
|
|
|
|
class SessionExpired
|
|
{
|
|
protected $session;
|
|
protected $timeout = 1200;
|
|
public function __construct(Store $session){
|
|
$this->session = $session;
|
|
}
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
|
|
|
|
public function handle($request, Closure $next)
|
|
{
|
|
$isLoggedIn = $request->path() != 'login';
|
|
if(! session('lastActivityTime'))
|
|
$this->session->put('lastActivityTime', time());
|
|
elseif(time() - $this->session->get('lastActivityTime') > $this->timeout){
|
|
$this->session->forget('lastActivityTime');
|
|
$cookie = cookie('intend', $isLoggedIn ? url()->current() : 'home');
|
|
// auth()->logout();
|
|
Auth::logout();
|
|
return Redirect::route('login');
|
|
}
|
|
$isLoggedIn ? $this->session->put('lastActivityTime', time()) : $this->session->forget('lastActivityTime');
|
|
return $next($request);
|
|
}
|
|
}
|