CodeIgniter Forums
DX_auth relogin updates the user_profile table. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: DX_auth relogin updates the user_profile table. (/showthread.php?tid=27555)



DX_auth relogin updates the user_profile table. - El Forum - 02-14-2010

[eluser]123wesweat[/eluser]
Hi,

I am having a problem with my logic. Somehow there is a new row added in the user_profile table when i logout and login again.

I do have an update method which triggers set_profile($user_id, $data). But this function updates a row it doesn't add a row, right??

Which function adds a row in table user_profile with the same user_id??? Only create_profile, right?? I don't trigger create_profile in my login logic>

The login method looks like
Code:
function login()
    {
        if ( ! $this->dx_auth->is_logged_in())
        {
            $val = $this->form_validation;        
            // Set form validation rules
            $val->set_rules('username', 'Username', 'trim|required|xss_clean');
            $val->set_rules('password', 'Password', 'trim|required|xss_clean');
            $val->set_rules('remember', 'Remember me', 'integer');
            //change some error messages
            $val->set_message('required', '%s  is verplicht');
            // Set captcha rules if login attempts exceed max attempts in config
            if ($this->dx_auth->is_max_login_attempts_exceeded())
            {
                $val->set_rules('captcha', 'Confirmation Code', 'trim|required|xss_clean|callback_captcha_check');
            }
                
            if ($val->run() AND $this->dx_auth->login($val->set_value('username'), $val->set_value('password'), $val->set_value('remember')))
            {
            //personal page
            $this->load->model('dx_auth/user_profile');
            $data['user_name'] = $this->dx_auth->get_username('username');
            $user_id = $this->dx_auth->get_user_id('username');
            $arrEmail=$this->_get_email($user_id);
            $user_profile_data = $this->user_profile->get_profile($user_id)->result();
            $data['profile_data'] = $user_profile_data[0];
            $data['email'] = $arrEmail->email;
            $data['auth_message'] = 'You are  logged in.';
            $this->load->view($this->dx_auth->logged_in_view, $data);
            
            }
            else
            {
                // Check if the user is failed logged in because user is banned user or not
                if ($this->dx_auth->is_banned())
                {
                    // Redirect to banned uri
                    $this->dx_auth->deny_access('banned');
                }
                else
                {                        
                    // Default is we don't show captcha until max login attempts eceeded
                    $data['show_captcha'] = FALSE;
                
                    // Show captcha if login attempts exceed max attempts in config
                    if ($this->dx_auth->is_max_login_attempts_exceeded())
                    {
                        // Create catpcha                        
                        $this->dx_auth->captcha();
                        
                        // Set view data to show captcha on view file
                        $data['show_captcha'] = TRUE;
                    }

                    $data['main_content'] = 'authFS/login_form';
                    $this->load->view('authFS/incs/template', $data);
                }
            }
        }
        else
        {    //already loggedin
            //load the profile page
            $this->load->model('dx_auth/user_profile');
            $data['user_name'] = $this->dx_auth->get_username('username');
            $user_id = $this->dx_auth->get_user_id('username');
            $arrEmail=$this->_get_email($user_id);
            $user_profile_data = $this->user_profile->get_profile($user_id)->result();
            //print_r($user_profile_data);
            $data['profile_data'] = $user_profile_data[0];
            $data['email'] = $arrEmail->email;
            $data['auth_message'] = 'You are  logged in.';
            $this->load->view($this->dx_auth->logged_in_view, $data);
        }
    }

Any suggestions?


DX_auth relogin updates the user_profile table. - El Forum - 02-14-2010

[eluser]123wesweat[/eluser]
ok i have enabled $this->output->enable_profiler(TRUE);

and know when i do a login i see the last 4 queries
Code:
0.0225      UPDATE DX_users SET last_ip = 'xxx.xx.xxx.180', last_login = '2010-02-14 20:30:19' WHERE `id` = '5'
0.0004      INSERT INTO DX_user_profile (user_id) VALUES ('5')
0.0001      SELECT email
FROM (DX_users)
WHERE `id` = '5'
0.0002      SELECT *
FROM (DX_user_profile)
WHERE `user_id` = '5'

and the
Code:
0.0004      INSERT INTO DX_user_profile (user_id) VALUES ('5')
is the trouble one? Any way to find where the querie takes place in my code?? I know shouldn't be that hard but i am stuck Sad


DX_auth relogin updates the user_profile table. - El Forum - 02-14-2010

[eluser]123wesweat[/eluser]
finally found it, turn out i had edit the DX_auth_event
Code:
function user_logged_in($user_id)
    {
        // Load models
        $this->ci->load->model('dx_auth/user_profile', 'user_profile');
        
// Create user profile
        $this->ci->user_profile->create_profile($user_id);
    }