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

[eluser]joytopia[/eluser]
Ben,

for some purposes I need a function to let the users enter their identity and password again without updating the session and remember_me.

Therefore I put an additional parameter $update in the login-methode:

library:

Code:
/**
     * login
     *
     * @return void
     * @author Mathew
     **/
    public function login($identity, $password, $remember=false, $update = TRUE) // Bernd Hueckstaedt: $update = FALSE only checks identity and Password
    {
        if ($this->ci->ion_auth_model->login($identity, $password, $remember, $update)) // Bernd Hueckstaedt: $update = FALSE only checks identity and Password
        {
            $this->set_message('login_successful');
            return TRUE;
        }

        $this->set_error('login_unsuccessful');
        return FALSE;
    }


model:

Code:
/**
     * login
     *
     * @return bool
     * @author Mathew
     **/
    public function login($identity, $password, $remember=FALSE, $update = TRUE) // Bernd Hueckstaedt: $update = FALSE only checks identity and Password
    {
        if (empty($identity) || empty($password) || !$this->identity_check($identity))
        {
            return FALSE;
        }

        $this->db->select($this->identity_column.', id, password, group_id')
            ->where($this->identity_column, $identity);

        if (isset($this->ion_auth->_extra_where))
        {
            $this->db->where($this->ion_auth->_extra_where);
        }

                $query = $this->db->where('active', 1)
                                      ->limit(1)
                               ->get($this->tables['users']);

        $result = $query->row();

        if ($query->num_rows() == 1)
        {
            $password = $this->hash_password_db($identity, $password);

            if ($result->password === $password)
            {
            
                if ($update) // Bernd Hueckstaedt: $update = FALSE only checks identity and Password
                {
                    $this->update_last_login($result->id);
    
                    $this->session->set_userdata($this->identity_column,  $result->{$this->identity_column});
                    $this->session->set_userdata('id',  $result->id); //kept for backwards compatibility
                    $this->session->set_userdata('user_id',  $result->id); //everyone likes to overwrite id so we'll use user_id
                    $this->session->set_userdata('group_id',  $result->group_id);
    
                    $group_row = $this->db->select('name')->where('id', $result->group_id)->get($this->tables['groups'])->row();
    
                    $this->session->set_userdata('group',  $group_row->name);
    
                    if ($remember && $this->config->item('remember_users', 'ion_auth'))
                    {
                        $this->remember_user($result->id);
                    }
                }

                return TRUE;
            }
        }

        return FALSE;
    }

Or is there a better way to do it?

Best regards
Bernd


Messages In This Thread
Ion Auth - Lightweight Auth System based on Redux Auth 2 - by El Forum - 06-01-2010, 01:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB