Handle ajax requests correctly

This commit is contained in:
Eike Foken
2011-08-10 19:26:44 +02:00
parent 5140deaca8
commit 24fbe455a1
2 changed files with 75 additions and 66 deletions

View File

@@ -35,7 +35,7 @@ function check_login() {
$public_controllers = array('auth');
$CI = & get_instance();
if (!$CI->access->loggedIn() && !in_array($CI->router->class, $public_controllers)) {
if (!$CI->input->is_ajax_request() && !$CI->access->loggedIn() && !in_array($CI->router->class, $public_controllers)) {
redirect('auth/login');
}
}

View File

@@ -25,6 +25,8 @@ class MY_Session extends CI_Session {
/**
* Creates a new session.
*
* @see CI_Session::sess_create()
*/
public function sess_create() {
$this->userdata = array(
@@ -45,13 +47,10 @@ class MY_Session extends CI_Session {
/**
* Updates an existing session.
*
* @see CI_Session::sess_update()
*/
public function sess_update() {
// skip the session update in case of an ajax call
if ($this->CI->input->is_ajax_request()) {
return;
}
// we only update the session every five minutes by default
if ($this->userdata['last_activity'] + $this->sess_time_to_update >= $this->now) {
return;
@@ -84,6 +83,16 @@ class MY_Session extends CI_Session {
// write the cookie
$this->_set_cookie($cookieData);
}
/**
* Destroys an existing session.
*
* @see CI_Session::sess_destroy()
*/
public function sess_destroy() {
parent::sess_destroy();
$this->userdata = array();
}
}
/* End of file MY_Session.php */