Last active
January 30, 2018 05:07
-
-
Save dwihujianto/c156308b7a31f970f4625c07314a731e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Session\Store; | |
class SessionExpireLogin | |
{ | |
protected $session; | |
protected $timeout = 5; // dalam detik | |
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) | |
{ | |
// ignore middleware kalau pas logout atau login -> sebenere kalau pake pure larapel ngga butuh, karena middleware e bisa diset di route | |
if ($request->path() == 'auth/login' || $request->path() == 'auth/logout') { | |
return $next($request); | |
} | |
if (time() - $this->session->get('lastActivityTime') > $this->getTimeOut()) { | |
$this->session->forget('lastActivityTime'); | |
Auth::logout(); | |
return redirect()->route('admin.login')->with('message', 'Waktu login sudah habis'); | |
} | |
return $next($request); | |
} | |
private function getTimeOut() | |
{ | |
return $this->timeout; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment