diff --git a/~dev_rating/application/classes/Controller/Handler/Session.php b/~dev_rating/application/classes/Controller/Handler/Session.php index 8f505469a292dcca7c74a30618be53529c31a47a..1b4f7dce9a68fbcbb0b6c85b4d4096d02fda54df 100644 --- a/~dev_rating/application/classes/Controller/Handler/Session.php +++ b/~dev_rating/application/classes/Controller/Handler/Session.php @@ -11,7 +11,7 @@ class Controller_Handler_Session extends Controller_Handler { $session = Session::instance(); if ($session->get('LoggedIn')) { $dif_time = $session->get('dif_time'); - $timeout = $session->get('timeout'); + $timeout = User::SESSION_LIFETIME; $remain = $timeout - $dif_time; if ($remain <= 0) { $this->completeSignOut(); @@ -23,4 +23,11 @@ class Controller_Handler_Session extends Controller_Handler { } $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 diff --git a/~dev_rating/media/js/profile.js b/~dev_rating/media/js/profile.js index 9caa3b304163a9a84195cf958881226aaa39adf7..01a94160c63b7873a50f8e92e41027078c82ead3 100644 --- a/~dev_rating/media/js/profile.js +++ b/~dev_rating/media/js/profile.js @@ -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) { timer = setTimeout(function() { $.ajax({ @@ -25,11 +40,11 @@ $(function() { data = $.parseJSON(data); wait = parseInt(data, 10); - if (wait <= 20) { - alert("it's over!"); + if (wait <= 10) { + closeSession(wait); return; } else { - setSessionTimer(wait-20); + setSessionTimer(wait-10); } } }); diff --git a/~dev_rating/modules/account/classes/Kohana/User.php b/~dev_rating/modules/account/classes/Kohana/User.php index 49a038682071850d43dd2b63a67cac7655af5854..848918946aa402bfe5079a3bab9c517258c377cc 100644 --- a/~dev_rating/modules/account/classes/Kohana/User.php +++ b/~dev_rating/modules/account/classes/Kohana/User.php @@ -8,6 +8,8 @@ class Kohana_User implements ArrayAccess { protected $_model; protected $_userInfo; + const SESSION_LIFETIME = 600; //seconds + /** * Вовзращает экземпляр класса (singleton-паттерн) * @@ -40,20 +42,17 @@ class Kohana_User implements ArrayAccess { if ($isSignedIn) { $last_time = $this->_session->get('last_time'); $cur_time = time(); - $timeout = 50; // second + $timeout = self::SESSION_LIFETIME; if (isset($last_time) AND $last_time != null) { $dif_time = $cur_time - $last_time; if ($dif_time > $timeout) { $this->completeSignOut(); - //throw HTTP_Exception::factory (403); - //return; } $this->_session->set('dif_time', $dif_time); } else { $this->_session->set('dif_time', $timeout+10); } - $this->_session->set('last_time', $cur_time); - $this->_session->set('timeout', $timeout); + $this->_session->set('last_time', $cur_time); } }