Welcome Guest, Not a member yet? Register   Sign In
Ion Auth - Lightweight Auth System based on Redux Auth 2

[eluser]Lucas Alves[/eluser]
My final solution to this was:

in the ion_auth model I created this methods:
Code:
public function check_session_validity()
{
    $this->db->where($this->tables['users'].'.id', $this->session->userdata('user_id'));
    $this->db->where($this->tables['users'].'.'.$this->identity_column, $this->session->userdata($this->identity_column));
    $this->db->where($this->tables['users'].'.group_id', $this->session->userdata('group_id'));
    $this->db->where($this->tables['users'].'.active', 1);

    return $this->db->count_all_results($this->tables['users']) > 0;
}


public function refresh_session_data(){
    $db_user_data = $this->get_user()->row();
    
    if(empty($db_user_data)){
        return FALSE;
    }
    
    if($db_user_data->active == 0){
        return FALSE;
    }
        
    $this->session->set_userdata($this->identity_column, $db_user_data->{$this->identity_column});
    $this->session->set_userdata('group_id', $db_user_data->group_id);
    $this->session->set_userdata('group', $db_user_data->group);
    
    return TRUE;
}


and in the constructor of the library, after check remembered, I put this code
Code:
//auto-login the user if they are remembered
if (!$this->logged_in() && get_cookie('identity') && get_cookie('remember_code'))
{
    $this->ci->ion_auth_model->login_remembered_user();
}
//check if the data in the session is equal to database data
elseif($this->logged_in() && !$this->ci->ion_auth_model->check_session_validity())
{
        //try to refresh the session data
    if(! $this->ci->ion_auth_model->refresh_session_data()){
                //oh, I can't update the session. Probably the user was deactivated
        $this->logout();
    }
}

What do you think?

As I said, I don't have access to github, but I'll try to get this friday at home...


Messages In This Thread
Ion Auth - Lightweight Auth System based on Redux Auth 2 - by El Forum - 08-11-2010, 01:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB