Welcome Guest, Not a member yet? Register   Sign In
Login redirects
#11

[eluser]doubleplusgood[/eluser]
Right, I seemingly now have the redirect working again. Big Grin
I have now changed the DB to match your example. So the account type is now set by a group field that is either 'dealer' or 'public.

The controller now successfully redirects to the relevant page when logged in;

Code:
public function login()
    {
        $email = $this->input->post('email');
        $password = $this->input->post('password');
        
        $logged_in = $this->auth->login($email, $password);

        if($logged_in == FALSE)
        redirect('auth/login');  //bad login buddy

        $uri = ($logged_in['group'] == 'dealer') ? 'vehicle_list' : 'vehicle_publiclist'; //what group are we in
        //die(print_r($logged_in));
        redirect('account/'.$uri);
    }

However, when a user now logs in, they always see the partials/subnav instead of the account specific partial;

Code:
$logged = $this->auth->logged_in();
if ( $logged['group'] == 'public' ){
    $this->load->view('partials/public_toolbar');
}elseif($logged['group'] == 'dealer' ){
    $this->load->view('partials/dealer_toolbar');
}else{
    $this->load->view('partials/subnav');
}

This is the print_r for $logged_in when i'm logged in as a dealer, which correctly shows the group set;

Array ( [id] => 46 [group_id] => 1 [email] => EMIAL [password] => HASH [salt] => SALT [first_name] => [last_name] => [reset_password_hash] => [active] => 1 [username] => dealertest [credits] => 10 [business_name] => dealer [business_address] => [business_region] => 9 [business_postcode] => [business_description] => [business_services] => [business_email] => [business_phone] => [business_website] => [business_photo] => [created_on] => 2010-05-25 20:59:34 [image1] => [image2] => [image3] => [image4] => [isDealer] => [isPublic] => [group] => dealer ) 1
#12

[eluser]pickupman[/eluser]
The code
Code:
$logged = $this->auth->logged_in();

Needs to be returning a user record. This is slightly different than the called made in your login method. Since the query is only done in the login method you can't count on that data for all of your pages whether logged in or not. What are you getting in $logged after this call?
#13

[eluser]doubleplusgood[/eluser]
When I add in the print_r here;

Code:
$logged = $this->auth->logged_in();
die(print_r($logged));
if ( $logged['group'] === 'public' ){
    $this->load->view('partials/public_toolbar');
}elseif($logged['group'] === 'dealer' ){
    $this->load->view('partials/dealer_toolbar');
}else{
    $this->load->view('partials/subnav');
}

I refresh the page and all I see is the number 11 where one of the partials should appear. Which is wierd because thatd oesn't seem to relate to anything about that logged in user's record.
#14

[eluser]pickupman[/eluser]
I would suggest having that function return a user's id and group. That should clear this up. I probably is returning TRUE which would be 1.
#15

[eluser]doubleplusgood[/eluser]
Would this be done in the view file or the controller?

I did try setting the group in the session data and then using something like this;

Code:
$user = $this->auth->get_user();
if ( $user['group'] === 'public' ){
    $this->load->view('partials/public_toolbar');
}elseif($user['group'] === 'dealer' ){
    $this->load->view('partials/dealer_toolbar');
}else{
    $this->load->view('partials/subnav');
}

But obviously this reported an error with group when a user is not logged in.
#16

[eluser]pickupman[/eluser]
The above would work as well. I found the best practice when return a function is to return FALSE if fail or some sort of data if TRUE. Then use:
Code:
function get_user(){
   $query = $this->db->get_where('user',array('user_id',$this->isLogged())); //get user by session id
   if($query->num_rows() > 0)
     return $query->result_array();

   return FALSE;
}

if($user != FALSE && $user['group'] == 'public'){
  $this->load->view('partials/public_toolbar');
}elseif($user != FALSE && $user['group'] == 'dealer'){
  $this->load->view('partials/dealer_toolbar');
}else{
  $this->load->view('partials/subnav');
}
#17

[eluser]doubleplusgood[/eluser]
Heh, so I changed the view as follows;

Code:
$user = $this->auth->get_user();
if($user != FALSE && $user['group'] == 'public'){
  $this->load->view('partials/public_toolbar');
}elseif($user != FALSE && $user['group'] == 'dealer'){
  $this->load->view('partials/dealer_toolbar');
}else{
  $this->load->view('partials/subnav');
}

and updated my Auth library as follows;

Code:
function logged_in()
        {
            return $this->_user['logged_in'];
        }
        
        //function get_user()
        //{
        //    return $this->_user;
        //}

        function get_user(){
           $query = $this->db->get_where('users',array('id',$this->isLogged())); //get user by session id
           if($query->num_rows() > 0)
             return $query->result_array();

           return FALSE;
        }

Replace my get_user with your code. But now I get this message when logged in or not;

Message: Undefined property: Auth::$db
Filename: libraries/Auth.php
Line Number: 96

Doh. Heh.
#18

[eluser]pickupman[/eluser]
I was only using that as an example. I don't know your table names or how your auth library get/sets a user id. You'll have to figure that out.
#19

[eluser]doubleplusgood[/eluser]
Think this is going to beat me today. Heh.




Theme © iAndrew 2016 - Forum software by © MyBB