Yii Framework Forum: AuthManager multiple roles - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

AuthManager multiple roles How to select a specific role to login Rate Topic: -----

#1 User is offline   marvin saruman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 09-July 12

Posted 10 July 2012 - 12:50 PM

Hello everyone,
I´ve been developing an application which has a permisssions section in which administrators can assign multiple roles to users. Based on these roles, I have a menu which must show only items for users who have a certain role assigned. For example:
User1 has role1 and role2

Menu: ITEM 1 (visible ONLY for role 1), ITEM 2 (visible only for role 2).

So, when User1 logs in, automatically authmanager retrieves role1 and role2 and assign it to User1, which makes the menu to show both ITEM1 and ITEM2.

What I want is:
Step 1) User1 logs in (no roles assigned so far)
Step 2) System identifies roles available for this user and asks him which one he wants to use
Step 3) Based on the single role User1 chose, either ITEM 1 or ITEM 2 should be displayed.

How can I achieve that?

I was trying to find the file in which the roles are assigned right after the UserIdentity.php is called, but no results so far =/

Thanks in advance
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 809
  • Joined: 02-July 10
  • Location:Central Poland

Posted 11 July 2012 - 01:10 AM

use RBAC (http://www.yiiframew...-access-control) or any of "RBAC" extensions available in repository... Exensions have advantage of providing UI to manage users and roles to basic RBAC.
red
0

#3 User is offline   marvin saruman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 09-July 12

Posted 11 July 2012 - 07:09 AM

View Postredguy, on 11 July 2012 - 01:10 AM, said:

use RBAC (http://www.yiiframew...-access-control) or any of "RBAC" extensions available in repository... Exensions have advantage of providing UI to manage users and roles to basic RBAC.


I´m actually using one extension in particular - Rights - but I´m still facing the problem. Probably because these extensions are all based on yii RBAC and by default (as far as I know), Yii loads all user´s roles at once when he logs in. I wish I could make this 'loading' lazy so I could choose which role to log in to.

Redguy, in the end of the text you sent me it says:
"Once we have established this hierarchy, the authManager component (e.g. CPhpAuthManager, CDbAuthManager) will load the authorization items automatically. "

I guess that´s where I want to modify the settings.
Any other suggestions?
0

#4 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 596
  • Joined: 15-March 11
  • Location:India

Posted 11 July 2012 - 08:04 AM

View Postmarvin saruman, on 10 July 2012 - 12:50 PM, said:

Hello everyone,
I´ve been developing an application which has a permisssions section in which administrators can assign multiple roles to users. Based on these roles, I have a menu which must show only items for users who have a certain role assigned. For example:
User1 has role1 and role2

Menu: ITEM 1 (visible ONLY for role 1), ITEM 2 (visible only for role 2).

So, when User1 logs in, automatically authmanager retrieves role1 and role2 and assign it to User1, which makes the menu to show both ITEM1 and ITEM2.

What I want is:
Step 1) User1 logs in (no roles assigned so far)
Step 2) System identifies roles available for this user and asks him which one he wants to use
Step 3) Based on the single role User1 chose, either ITEM 1 or ITEM 2 should be displayed.

How can I achieve that?

I was trying to find the file in which the roles are assigned right after the UserIdentity.php is called, but no results so far =/

Thanks in advance


Well according to me its not related to any extension. You have created your Own authorization system.Which is great.The thing which you are trying to do here is a logical approach.

So, what you can do here is to force user to select a role.After Login Just redirect user to any other page where give a possibility to user to choose a role.Then according to selected Role.Just assign a selected role with setState() method.
CodeSutra
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users