Welcome Guest, Not a member yet? Register   Sign In
Two auth areas with Community Auth
#1

I'm trying to set up two areas that require authentication, using Community Auth. One will be for front-end users, one for CMS users. I'm getting a bit confused about the routing for this.

So I have two groups set up (public and cms) in config/authentication.php. I control access to my cms controller with
Code:
$this->require_group('cms');

and to my public controller with
Code:
$this->require_group('public');

The problem is in each case if there is no user logged in, Community Auth redirects to the same login page. I need two completely different login areas/pages, one for public and one for admin.

From looking at core/Auth_Controller.php it seems that require_group calls a function _redirect_to_login_page, which uses the constant LOGIN_PAGE to get the redirect destination. I don't want to modify the core here, so is there another way of having two login pages? Thanks in advance.
Reply
#2

(This post was last modified: 10-03-2015, 02:23 PM by skunkbad.)

Have you actually defined the groups? If you have a group named "cms", then in config/authentication.php you need to define the roles that belong to the group. So for instance, if have this:


PHP Code:
$config['groups'] = array(
    
'cms' => 'editor,admin',
    
'public' => 'reader,customer'
); 

That is how to use the authentication by group. What you are saying is, if the user is an editor or admin then give them access to anything that requires cms group access. If the user is a reader or customer, give them access to anything that requires public access.
Reply
#3

Thanks for answering. Yes, I've already defined those groups -- my question was more about the routing. require_group is working fine, but I want it to redirect to a different login page for each group. Sorry if I wasn't clear in the original post.
Reply
#4

(10-04-2015, 05:04 AM)gdansk Wrote: Thanks for answering. Yes, I've already defined those groups -- my question was more about the routing. require_group is working fine, but I want it to redirect to a different login page for each group. Sorry if I wasn't clear in the original post.

You could certainly create another login page, and make it available to site users. Make sure to review the setting in config/authentication.php that allows the new login page:


Code:
$config['allowed_pages_for_login'] = array();


If what you mean is that you would like to redirect somebody AFTER they have logged in, based their role, then there would be a number of ways to do this. I would probably try to fiddle around with making the default login redirect an anonymous function.


Code:
$config['default_login_redirect'] = function(){
  if( config_item('auth_role') == 'employee' )
  {
    return 'employees/index';
  }
  else if( config_item('auth_role') == 'admin' )
  {
      //....
  }
};
Reply
#5

Great -- thanks very much, I'll give this a go.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB