Handle ajax requests correctly
This commit is contained in:
@@ -35,7 +35,7 @@ function check_login() {
|
|||||||
$public_controllers = array('auth');
|
$public_controllers = array('auth');
|
||||||
|
|
||||||
$CI = & get_instance();
|
$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');
|
redirect('auth/login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,8 @@ class MY_Session extends CI_Session {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new session.
|
* Creates a new session.
|
||||||
|
*
|
||||||
|
* @see CI_Session::sess_create()
|
||||||
*/
|
*/
|
||||||
public function sess_create() {
|
public function sess_create() {
|
||||||
$this->userdata = array(
|
$this->userdata = array(
|
||||||
@@ -45,13 +47,10 @@ class MY_Session extends CI_Session {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates an existing session.
|
* Updates an existing session.
|
||||||
|
*
|
||||||
|
* @see CI_Session::sess_update()
|
||||||
*/
|
*/
|
||||||
public function 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
|
// we only update the session every five minutes by default
|
||||||
if ($this->userdata['last_activity'] + $this->sess_time_to_update >= $this->now) {
|
if ($this->userdata['last_activity'] + $this->sess_time_to_update >= $this->now) {
|
||||||
return;
|
return;
|
||||||
@@ -84,6 +83,16 @@ class MY_Session extends CI_Session {
|
|||||||
// write the cookie
|
// write the cookie
|
||||||
$this->_set_cookie($cookieData);
|
$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 */
|
/* End of file MY_Session.php */
|
||||||
|
|||||||
Reference in New Issue
Block a user