konapaz
(Konapaz)
November 20, 2012, 2:01pm
1
Hi, how to set a custom role for user on UserIdentity class?
I want to set a role when "authenticate" function authedicate the user.
I have write in function the $this->setState(‘roles’, ‘admin’);
and in accessRules() of Controller the ‘roles’=>‘myauth’ but not work
Any suggestion?
Thanks
konapaz
(Konapaz)
November 21, 2012, 1:33am
2
I found out that $this->setState(‘roles’, ‘admin’) is not appropriate method to set a role to user
So, how can I set a role to the current user?
Keith
(Kburton)
November 21, 2012, 8:46am
3
Why do you wish to do it dynamically? You must already be using some sort of hard coded logic to determine which user gets which roles.
konapaz
(Konapaz)
November 21, 2012, 12:33pm
4
Hi Keith, thank you for responsing
In my system I have two type of users ‘editor’ and ‘author’.
So I want to check if a user has the permissions for each controller/action using in accessRules the ‘role’=>‘editor’ or ‘role’=>‘author’.
I dont want to use AR for users because there are only few users stored in php file as array
So how can I set a simple role for the user like $user->addRole(‘author’) ?
Thank you
Keith
(Kburton)
November 21, 2012, 12:49pm
5
If you want to avoid using the database, you could consider CPhpAuthManager, which will persist your role assignments to the file system. I don’t think there’s a built in way to persist to just the user’s session, which is what you seem to be suggesting.
I’d suggest configuring your auth file using the class above and let it handle the RBAC thereafter, rather than trying to do it all dynamically.
EDIT:
Useful article.
konapaz
(Konapaz)
November 21, 2012, 10:04pm
6
Keith:
If you want to avoid using the database, you could consider CPhpAuthManager, which will persist your role assignments to the file system. I don’t think there’s a built in way to persist to just the user’s session, which is what you seem to be suggesting.
I’d suggest configuring your auth file using the class above and let it handle the RBAC thereafter, rather than trying to do it all dynamically.
EDIT:
Useful article.
Ok Keith, I will try it in this way
Thanks