mohit-singh/zf2auth-acl 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mohit-singh/zf2auth-acl

Composer 安装命令:

composer require mohit-singh/zf2auth-acl

包简介

This is ACL module plug with zfcuser module this is heighly configurable abd provide different services at controller, view and module level.

README 文档

README

Branch: zfcuser_acl

This this the ZF2 ACL module forked from arvind2110/ZF2-Auth-ACL and Plugged with zfcuser module. it will provide role base access and switching between roles , provides custom permission denied template , plug ins to access role at controller , view and module level. All the role, resource and permission are stored in databases.

How to Use it

using composer add

  "require" : {
       ...
    "mohit-singh/zf2auth-acl": "V1.0.1"
  }

Enable the module in application.config.php

 'modules' => array(
	...
        'ZF2AuthAcl'
    ),

then copy and rename the following,

copy vendor/mohit-singh/zf2auth-acl/config/aclAuth.local.php.dist to config/autoload/aclAuth.local.php

Add the depended table from

vendor/mohit-singh/zf2auth-acl/data/data.sql

ADD role for user in table e.g.

INSERT INTO `role` (`role_name`, `status`) VALUES ('Role1', 'Active');
INSERT INTO `role` (`role_name`, `status`) VALUES ('Role2', 'Active');
INSERT INTO `role` (`role_name`, `status`) VALUES ('Role3', 'Active');

ADD resources, resources are your controller name through which you invoke your controller, for me it's "Application\Controller\Index" e.g.

INSERT INTO `resource` (`resource_name`) VALUES ('Application\\Controller\\Index');

ADD Permissions , permission are the action, you have to associated all action with there controller resource e.g.

INSERT INTO `permission` (`permission_name`, `resource_id`) VALUES ('index', 1);
INSERT INTO `permission` (`permission_name`, `resource_id`) VALUES ('show', 1);

ADD role permission , you have to decided which role have which permission e.g.

INSERT INTO `role_permission` (`role_id`, `permission_id`) VALUES (1, 1);
INSERT INTO `role_permission` (`role_id`, `permission_id`) VALUES (1, 2);

ADD user role , you have to decide which user have which role , this can be done manually or using some custom script.

INSERT INTO `user_role` (`user_id`, `role_id`) VALUES (1, 1);
INSERT INTO `user_role` (`user_id`, `role_id`) VALUES (2, 2);

NOTE:- please check the aclAuth.local.php con-fig for the default role, it Should be one of the role whatever you insert in the database.

after all these configuration is done you are ready to use ACL module

Services

Remove ACL from a URL and make it global, access to all , add link here

// in config/autoload/aclAuth.local.php
'globalList' => array(
		      'Application\Controller\Index-index'
	   ),

Remove ACL from a URL and make it global before login , add link here

// in config/autoload/aclAuth.local.php
'beforeLoginList' => array(
		      'Application\Controller\Index-index'
	   ),

Custom template for permission denied, add new template path here

// in config/autoload/aclAuth.local.php
'ACL_Template' =>'zf2-auth-acl/index/permission.phtml'

Role base services at controller

// Check user has role or not , return true, false
$this->userAuthRole()->userHasRole();

//Get  user current role
$this->userAuthRole()->getRoleName();

//get All valid role for the current user
$this->userAuthRole()->getUserValidRole();

//Switch between roles
$this->userAuthRole()->switchRole('ADMIN');

at view level

// Check user has role or not , return true, false
$this->roleAuth()->userHasRole();

//Get  user current role
$this->roleAuth()->getRoleName();

//get All valid role for the current user
$this->roleAuth()->getUserValidRole();

//Switch between roles
$this->roleAuth()->switchRole('ADMIN');

at module level

$roleAtuth = $serviceManager->get('roleAuthService');

// Check user has role or not , return true, false
$roleAtuth->userHasRole();

//Get  user current role
$roleAtuth->getRoleName();

//get All valid role for the current user
$roleAtuth->getUserValidRole();

//Switch between roles
$roleAtuth->switchRole('ADMIN');

It Also provide cache mechanism to store role, resource and permission in cache. you can configure the caching here

    /**
     * This cache is used the disk file system to store date with the following options.
     */ 
    'fileCache' => array(
        'cache_dir' => './data/cache',
        'namespace' => 'systemCache',
        'dir_level' => 2,
        'filePermission' => 0666,
        'dirPermission' => 0755
    ),

you can also access file system cache in your project like this

// store item in filesystem cache
        $this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->setItem('foo', 'taxi');


// get item from filesystem cache
        echo 'Cached Item is:- '.$this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->getItem('foo');

you are using file system cache so you have to give permission to the cache folder

> sudo chmod -R 0777 data/cache

统计信息

  • 总下载量: 650
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 18
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-06-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固