![]() |
Login redirects - 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: Login redirects (/showthread.php?tid=30765) Pages:
1
2
|
Login redirects - El Forum - 05-25-2010 [eluser]doubleplusgood[/eluser] Hi there, I have a working login form for my site. But I need to expand on this so that different user types are redirected to different pages. Currently, when everyone logs in, they are redirected to account/vehicle_list. But I now want all users who have 'isPublic' in their db record to be redirected to account/vehicle_publiclist and all users with 'isDealer' redirected to account/vehicle_list. My account controller has the following functions; Code: public function index() And my Auth library has; Code: function login($email, $password) So, I'm wondering if someone might be able to help me figure out how to redirect users based on the isDealer or isPublic being set in their db record? Thanks, Neil Login redirects - El Forum - 05-25-2010 [eluser]pickupman[/eluser] Rather than returning just TRUE, return something more meaningful like at least a user_id or return the whole $user array/result. Still pass FALSE on a failed login. Then you can test if the login has succeeded. Code: //Auth library Login redirects - El Forum - 05-25-2010 [eluser]doubleplusgood[/eluser] Awesome, thank you very much man. Now i just have to figure out how to show a different toolbar of account links, based on the type of account logged in. ![]() I currently have a view layout with the following code; Code: if ( $this->auth->logged_in() ) But ideally, i need a third option here, to show a partials/myaccountpublic if the isPublic group is set to 1. So if a dealer is logged in with isDealer set in their db record, then they would just see the partials/myaccount. In the Auth library, there is the function logged_in as follows; Code: function logged_in() Login redirects - El Forum - 05-25-2010 [eluser]pickupman[/eluser] Code: $logged = $this->auth->logged_in(); Login redirects - El Forum - 05-25-2010 [eluser]doubleplusgood[/eluser] Thanks man. The redirect based on whether the user is a Dealer or Public seems to work fine, but both account types see the public_toolbar with the following code; Code: $logged = $this->auth->logged_in(); My code is slightly different to your solution as the DB stores account types like so; isDealer => 0 or 1 isPublic => 0 or 1 Login redirects - El Forum - 05-25-2010 [eluser]pickupman[/eluser] The double equals may still be evaluating to boolean (isset). Try triple === Code: $logged = $this->auth->logged_in(); Login redirects - El Forum - 05-25-2010 [eluser]doubleplusgood[/eluser] Hmm, weird. Doesn't seem to work with triple === either. :S Login redirects - El Forum - 05-25-2010 [eluser]doubleplusgood[/eluser] Damn, just realised the login redirect isn't actually working either. Thought it was. ![]() Do i need to set the 'isDealer' or 'isPublic' in the session data perhaps? Really appreciate you taking the time to help me on this. Login redirects - El Forum - 05-25-2010 [eluser]pickupman[/eluser] Really no need for the session unless, your auth library is setting some sort of variable. Did you change your login method to return the user profile rather than TRUE/FALSE? If so, what do you get when you var_dump($logged_in) in your controller after it calls the login method? You will probably need to comment out the redirects in order to see this. Login redirects - El Forum - 05-25-2010 [eluser]doubleplusgood[/eluser] Hey man, so I did a print_r for $logged_in and it displayed this; Code: Array ( [id] => 46 [group_id] => 1 [email] => MYEMAIL [password] => PASSWORDHASH [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] => ) 1 The thing is, that this array is misreporting as the account that I am actually logged in as has the following set in the DB record; isDealer => 1 isPublic => 0 As you will see above, the array is saying that isPublic is set to 1 for this user. :S |