Skip to content
Snippets Groups Projects
Commit 37a7da7b authored by PavelBegunkov's avatar PavelBegunkov
Browse files

session: alert disappearance

parent bb276a05
Branches
Tags
No related merge requests found
...@@ -11,7 +11,7 @@ class Controller_Handler_Session extends Controller_Handler { ...@@ -11,7 +11,7 @@ class Controller_Handler_Session extends Controller_Handler {
$session = Session::instance(); $session = Session::instance();
if ($session->get('LoggedIn')) { if ($session->get('LoggedIn')) {
$dif_time = $session->get('dif_time'); $dif_time = $session->get('dif_time');
$timeout = $session->get('timeout'); $timeout = User::SESSION_LIFETIME;
$remain = $timeout - $dif_time; $remain = $timeout - $dif_time;
if ($remain <= 0) { if ($remain <= 0) {
$this->completeSignOut(); $this->completeSignOut();
...@@ -23,4 +23,11 @@ class Controller_Handler_Session extends Controller_Handler { ...@@ -23,4 +23,11 @@ class Controller_Handler_Session extends Controller_Handler {
} }
$this->response->body(json_encode($remain)); $this->response->body(json_encode($remain));
} }
public function action_closeSession() {
if ($session->get('LoggedIn')) {
$this->completeSignOut();
}
$this->response->body(json_encode(0));
}
} }
\ No newline at end of file
...@@ -16,6 +16,21 @@ $(function() ...@@ -16,6 +16,21 @@ $(function()
}); });
function closeSession(time) {
if (time < 0)
time = 0;
setTimeout(function() {
$.ajax({
type: "POST",
url: URLdir + "handler/Session/closeSession",
success: function(data) {}
});
window.location.replace(URLdir);
}, time*1000);
}
function setSessionTimer(time) { function setSessionTimer(time) {
timer = setTimeout(function() { timer = setTimeout(function() {
$.ajax({ $.ajax({
...@@ -25,11 +40,11 @@ $(function() ...@@ -25,11 +40,11 @@ $(function()
{ {
data = $.parseJSON(data); data = $.parseJSON(data);
wait = parseInt(data, 10); wait = parseInt(data, 10);
if (wait <= 20) { if (wait <= 10) {
alert("it's over!"); closeSession(wait);
return; return;
} else { } else {
setSessionTimer(wait-20); setSessionTimer(wait-10);
} }
} }
}); });
......
...@@ -8,6 +8,8 @@ class Kohana_User implements ArrayAccess { ...@@ -8,6 +8,8 @@ class Kohana_User implements ArrayAccess {
protected $_model; protected $_model;
protected $_userInfo; protected $_userInfo;
const SESSION_LIFETIME = 600; //seconds
/** /**
* Вовзращает экземпляр класса (singleton-паттерн) * Вовзращает экземпляр класса (singleton-паттерн)
* *
...@@ -40,20 +42,17 @@ class Kohana_User implements ArrayAccess { ...@@ -40,20 +42,17 @@ class Kohana_User implements ArrayAccess {
if ($isSignedIn) { if ($isSignedIn) {
$last_time = $this->_session->get('last_time'); $last_time = $this->_session->get('last_time');
$cur_time = time(); $cur_time = time();
$timeout = 50; // second $timeout = self::SESSION_LIFETIME;
if (isset($last_time) AND $last_time != null) { if (isset($last_time) AND $last_time != null) {
$dif_time = $cur_time - $last_time; $dif_time = $cur_time - $last_time;
if ($dif_time > $timeout) { if ($dif_time > $timeout) {
$this->completeSignOut(); $this->completeSignOut();
//throw HTTP_Exception::factory (403);
//return;
} }
$this->_session->set('dif_time', $dif_time); $this->_session->set('dif_time', $dif_time);
} else { } else {
$this->_session->set('dif_time', $timeout+10); $this->_session->set('dif_time', $timeout+10);
} }
$this->_session->set('last_time', $cur_time); $this->_session->set('last_time', $cur_time);
$this->_session->set('timeout', $timeout);
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment