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 {
$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
......@@ -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);
}
}
});
......
......@@ -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);
}
}
......
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