mdmsoft / yii2-admin

Auth manager for Yii2 (RBAC Manager)
GNU General Public License v3.0
1.16k stars 574 forks source link

Setting permissions for guests (not logged in users) #64

Open sosojni opened 9 years ago

sosojni commented 9 years ago

Is it possible to set up permissions for guests? What i would like to do is to assign a role to all guests so they are able to access login / register / resend password / request new password pages.

After some digging, i managed to open those pages to unregistered users by change in config\web.php

From:

'as access' => [ 'class' => 'mdm\admin\components\AccessControl', 'allowActions' => ['admin/*'] ],

To: 'as access' => [ 'class' => 'mdm\admin\components\AccessControl', 'allowActions' => [ 'admin/*', 'user/security/login', 'user/registration/register', 'user/registration/resend', 'user/recovery/request', ] ],

Is it possible to do this from inside admin menu? I tryed to create role "guest" and "Guest" but had no effect.

mdmunir commented 9 years ago

No, you cannot. assigment only for registered user. yii\rbac\BaseManager has property $defaultRole, you can use it for assign to guest http://www.yiiframework.com/doc-2.0/yii-rbac-basemanager.html#$defaultRoles-detail

sosojni commented 9 years ago

I suggest you add this to your documents for people that are new to Yii2 and RBAC like myself. Basicly, only thing that needs to be done to manage "guest" from your extension is to: 1) create role Guest 2) add

'components' => [ ... 'authManager' => [ ... 'defaultRoles' => ['Guest'], ], ...

to config/web.php

So basicly (from freshmen point of view), yes, you can work with unregistered users, all you have to do is add guest role (it can be names "unregistered" or any other way) to config as default one. Please, add this to your documents and your extension will be much user friendly...er....

golles commented 9 years ago

that solution doesn't work for me.

sosojni commented 9 years ago

Can we see your config and are you sure your "defaultRoles' has same name as role you created in administration?

sosojni commented 9 years ago

Did you set up "Standard View" permission correctly to allow access to "login" page?

On 10.12.2014. 8:54, Ronal Gorba Timothy wrote:

Doesn't work for me too. I couldnt open any page to login such as site/login & user/security/login. Dont know why. These are the pict: screenshot 2014-12-10 14 51 49 https://cloud.githubusercontent.com/assets/3026828/5372511/671dfdea-807c-11e4-9753-94924c442d1e.png screenshot 2014-12-10 14 52 07 https://cloud.githubusercontent.com/assets/3026828/5372515/73b8ef7e-807c-11e4-9488-743ba9daee67.png

— Reply to this email directly or view it on GitHub https://github.com/mdmsoft/yii2-admin/issues/64#issuecomment-66415761.


This email has been checked for viruses by Avast antivirus software. http://www.avast.com

Clyff commented 9 years ago

Thats perfect, thanks @sosojni !

rlucian commented 8 years ago

This really belongs to the index of the documentation, along with installation and configuration...
10q very much @sosojni

ossse commented 5 years ago

there is a problem where we set property defaultRoles as guest role, since defaultRoles by code is assign to all registered user, so the problem is where there is condition we want to assign a permission only to guest, not to registered user.