Welcome Guest, Not a member yet? Register   Sign In
Using tank_auth for both front end user registration and login and back end admin login
#1

[eluser]Amitabh Roy[/eluser]
Well, I have been planning to use tank_auth in my current project.
Using it to validate either ther front end users or the admin users is fine. But I don't see way how I will be able to use the tank_auth system to validate both front end users(registered website members) and website admins(for the admin panel).

Basically there is no separate admin table(I would like to keep the admin accounts in a separate table). And I don't see any flexibility in the login function in the controller/auth.php and libraries/Tank_auth.php to allow both front end and admin login.
My admin controllers are in controllers/admin/

Anybody who have faced this problem before? Any solutions by extending the auth class or the Tank_auth class?
#2

[eluser]Amitabh Roy[/eluser]
Thanks @TheFuzzy0ne, late reply I know.8-/
After many rounds of discussions and deliberations we decided to go for Google Oauth2 for
validating the front end users and use tank auth for the admin. As such the issue is no more valid.

Now have to check out Google Oauth libraries/implementations for Codeigniter ;-)
#3

[eluser]vbsaltydog[/eluser]
Use ion_auth for front end and back end logins.

ion_auth has user groups so user accounts can be set to member, admin, moderator, etc.

Then just force login on restricted controllers and test the user group for authorization.

#4

[eluser]Amitabh Roy[/eluser]
[quote author="vbsaltydog" date="1327159673"]Use ion_auth for front end and back end logins.

ion_auth has user groups so user accounts can be set to member, admin, moderator, etc.

Then just force login on restricted controllers and test the user group for authorization.

[/quote]

Thanks @vbsaltydog, the user group separation in ion_auth looks promising. Will definitely give it a try.
#5

[eluser]jwright[/eluser]
I came across the same issue with Tank Auth. No groups support out of the box. I extended Tank Auth with my own groups support by...

Adding a 'group_id' column to the users table.

Extending the Tank Auth library and Users model (by creating new classes that inherit/extend them, Tank_auth_groups and ta_groups_users).

Replacing every where Tank Auth is loaded and loading my 'Tank_auth_groups' class instead.



And for admin panel support I...

Added an 'is_admin()' function to my Tank_auth_groups class.

Created an Admin base controller that checks if the current user 'is_admin()' in the constructor. Then have all your admin controllers extend/inherit from the admin base controller.



The groups support I've blogged about in detail and packaged all the code on github ( 'tank_auth_groups') for a drop in install if you're interested in checking it out.

The github package doesn't include the admin base controller, but it is basically this...

Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

require APPPATH."core/Base_Controller.php";

class Admin_Base extends Base_Controller {
    
function __construct()
{
  parent::__construct();
                
                $this->load->library('tank_auth_groups','', 'tank_auth');
                
                if(!$this->tank_auth->is_admin())
                {
                    show_404();
                    exit;
                }
}
}

#6

[eluser]Amitabh Roy[/eluser]
[quote author="jwright" date="1328029203"]I came across the same issue with Tank Auth. No groups support out of the box. I extended Tank Auth with my own groups support by...

Adding a 'group_id' column to the users table.

Extending the Tank Auth library and Users model (by creating new classes that inherit/extend them, Tank_auth_groups and ta_groups_users).

Replacing every where Tank Auth is loaded and loading my 'Tank_auth_groups' class instead.



And for admin panel support I...

Added an 'is_admin()' function to my Tank_auth_groups class.

Created an Admin base controller that checks if the current user 'is_admin()' in the constructor. Then have all your admin controllers extend/inherit from the admin base controller.



The groups support I've blogged about in detail and packaged all the code on github ( 'tank_auth_groups') for a drop in install if you're interested in checking it out.

The github package doesn't include the admin base controller, but it is basically this...

Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

require APPPATH."core/Base_Controller.php";

class Admin_Base extends Base_Controller {
    
function __construct()
{
  parent::__construct();
                
                $this->load->library('tank_auth_groups','', 'tank_auth');
                
                if(!$this->tank_auth->is_admin())
                {
                    show_404();
                    exit;
                }
}
}

[/quote]

Thanks @jwright. Impressive indeed. Am glad to see someone have been down this path before.
I was on a holiday, right now I am going through your blog post. For my current project which needed this feature,
for the front end user authentication we decided to go for
OAuth with Federated Login (Hybrid Protocol) , as the users will be using google api extensively.

The back end is in tank_auth though. But this is definitely very helpful for future projects, where I might face the same situation again.
Thanks once again for the post! It is very helpful indeed! :coolsmile:

#7

[eluser]jwright[/eluser]
@Amitabh , thanks! I hope you find it useful when you need it.
#8

[eluser]Popescu Mihaela[/eluser]
@jwright - I am using your system but there is one problem: when I close the browser the group_id data dissapears from column user_data inside table ci_sessions, then when I open the browser again there is no group_id in the session so the entire system fails.
#9

[eluser]Kinsbane[/eluser]
[quote author="Popescu Mihaela" date="1332238802"]@jwright - I am using your system but there is one problem: when I close the browser the group_id data dissapears from column user_data inside table ci_sessions, then when I open the browser again there is no group_id in the session so the entire system fails.[/quote]

Hi, I believe jwright meant to make a new column, "group_id" in the users table - not in the sessions table.

How I have my schema laid out is kinda like this:

Code:
[tbl_users]          [tbl_user_groups]
user_id                                      
user_login                                  
user_password                        
user_group_id --FK-> group_id
                     group_name

It's a one-to-many relationship (hence the FK, for "foreign key"), so, any group can be assigned to one or more users, but, users may only be assigned to one group.




Theme © iAndrew 2016 - Forum software by © MyBB