Kohana/PHP Auth fails while issusing a request through AJAX -
i have base class inherited controllers. having function in base class determines logged in users role using auth. once users role determine variable $loggedin_role set.
this method correctly called on initial page load, later issuing ajax calls check whether user still logged in, @ time auth::logged_in() returning 0.
the kohana version using 3.3
can 1 please suggest best approach circumvent issue. thanks.
to login -
if ($validobj->check()) { if (auth::instance()->login($_post['email'], $_post['password'],false)) { $this->dopostloginjobs(); } else { $this->manageerror(controller_application::msgwrongusercredentials); } } else { $this->form_errors = $validobj->errors(''); }
to logout -
public function action_logout() { $loggedout = auth::instance()->logout(); if ($loggedout) http::redirect ('/home/'); // redirects home page. }
inside controller_application . base class of controllers
public function determineuserrole() { $this->loggedin_role = controller_application::none; try { if (auth::instance()->logged_in('freelancer')) { $this->loggedin_role = controller_application::freelancer; $this->loggedin_id = auth::instance()->get_user()->pk(); } else if (auth::instance()->logged_in('employer')) { $this->loggedin_role = controller_application::employer; $this->loggedin_id = auth::instance()->get_user()->pk(); } } catch (gettrix_exception $exc) { $this->manageerror(controller_application::redirectnonrecoverableerror); } public function before() { if ($this->request->is_ajax()) { $this->auto_render = false; } $this->determineuserrole(); if($this->auto_render==true){ parent::before(); $this->template->content = ''; $this->template->styles = array(); $this->template->scripts = array(); view::set_global('site_name', 'thewebteam'); view::bind_global('form_errors', $this->form_errors); view::bind_global('loggedin_role', $this->loggedin_role); view::bind_global('loggedin_id', $this->loggedin_id); view::bind_global('invitedemail', $this->invitedemail); view::bind_global('inviteduniqueid', $this->inviteduniqueid); view::bind_global('scripts', $this->template->scripts); view::bind_global('styles', $this->template->styles); }
//this inside home page controller, lists jobs logged in user.
public function action_joblist() { echo auth::instance()->logged_in() . //the state holds initial state, doesn't //change when user logged out or logged in. }
please note action_joblist() called via ajax/jquery call.
the issue fixed following instructions given in link : http://forum.kohanaframework.org/discussion/9619/session-timeout-corruption-problems/p1
Comments
Post a Comment