developeruz / easyii-rbac-module
为EasyiiCMS提供基于角色的访问控制
dev-master
2017-02-03 16:53 UTC
Requires
- developeruz/easyii-user-module: dev-master
- developeruz/yii2-db-rbac: *
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-14 20:04:15 UTC
README
本模块允许添加Rbac模块到Easy yii2 cms
安装指南
请按照以下说明安装EasyiiCMS用户模块,然后再继续
$ php composer.phar require developeruz/easyii-rbac-module "dev-master"
替换app/config/web.php
中的最后一行
$config = array_merge_recursive($config, require($webroot . '/vendor/developeruz/easyii-user-module/config/user_module_config.php'), require($webroot . '/vendor/noumo/easyii/config/easyii.php')); $config['components']['user'] = [ 'identityClass' => 'developeruz\easyii_user\models\User' ]; return $config;
为
$config = array_merge_recursive($config, require($webroot . '/vendor/developeruz/easyii-user-module/config/user_module_config.php'), require($webroot . '/vendor/developeruz/easyii-rbac-module/config/rbac_module_config.php'), require($webroot . '/vendor/noumo/easyii/config/easyii.php')); $config['components']['user'] = [ 'identityClass' => 'developeruz\easyii_rbac\models\User' ]; return $config;
在app/config/console.php
和app/config/web.php
中添加authManager到components
'components' => [ ... 'authManager' => [ 'class' => 'yii\rbac\DbManager', ], ]
运行authManager迁移
php yii migrate --migrationPath=@yii/rbac/migrations/
运行迁移
php yii migrate --migrationPath=@vendor/developeruz/easyii-rbac-module/migrations
打开用户CRUD页面(url admin/user
),您将在操作按钮列中看到“更改用户角色”按钮。点击它并将“Admin”角色分配给管理员用户。
在app/config/web.php
中添加行为
'components' => [ ... ], 'modules' => [ ... ], 'as AccessBehavior' => [ 'class' => \developeruz\db_rbac\behaviors\AccessBehavior::className(), 'login_url' => '/admin/sign/in', 'rules' => [ 'user/security' => [['actions' => ['login'], 'allow' => true ], ['actions' => ['logout'], 'roles' => ['@'], 'allow' => true ]], 'user/settings' => [['roles' => ['@'], 'allow' => true ]], 'admin/sign' => [['actions' => ['in'], 'allow' => true], ['actions' => ['out'], 'roles' => ['@'], 'allow' => true ]], 'site' =>[[ 'allow' => true]], 'articles' =>[[ 'allow' => true]], 'gallery' =>[[ 'allow' => true]], 'news' =>[[ 'allow' => true]], ], ]
在rules
中添加所有公共控制器。
如果用户没有访问管理面板的权限,则通过添加CSS display:none
,在主页面上隐藏管理员工具栏。这是被迫的解决方案,因为Easy yii2 cms不允许覆盖这部分。我将创建PR并在可能的情况下更改此模块的行为。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。