protected function _authenticate()
 {
     //var_dump($this->session->all_userdata());die();
     $this->load->model('Do_auth');
     $userSess = new Usersess();
     //var_dump($this->_auth_err);die();
     # Check session
     if (!empty($userSess->errors)) {
         $this->_auth_err['session'] = 'Invalid value or data structure';
     } else {
         # check session if set and not empty
         if (!$userSess->isInit()) {
             # check saved session instead
             $session_data = $this->Do_auth->getBySessionId($this->input->cookie('ci_session'));
             if ($session_data && $session_data->remember_me == '1') {
                 # fetch user
                 $this->load->model('Do_user');
                 $user_data = $this->Do_user->getUserById($session_data->user_id);
                 # set session
                 $userSess->updateUserSess($user_data->user_id, $user_data->user_given_name, $user_data->user_family_name, $user_data->user_member_of);
                 if (!empty($userSess->errors)) {
                     $this->_auth_err['session'] = 'Invalid value or data structure';
                 }
             } elseif ($session_data && $session_data->remember_me == '0') {
                 $this->_auth_err['login'] = '******';
             } else {
                 $this->_auth_err['cookie'] = 'Cookie authentication error';
             }
         }
     }
     if (!empty($this->_auth_err)) {
         redirect(site_url('Login'));
     }
 }
Ejemplo n.º 2
0
 public function logout()
 {
     $this->_CI->load->model('Do_auth');
     $userSess = new Usersess();
     $session_id = get_cookie('ci_session');
     # current session
     $session_data = $this->_CI->Do_auth->getBySessionId($session_id);
     if ($session_data->remember_me == '1') {
         $this->_CI->Do_auth->removeSession($session_id);
     }
     $userSess->destroy();
 }