nrayann/my-acl

CakePHP 插件,用于通过友好的界面管理 ACL。

安装: 34

依赖: 0

建议: 0

安全: 0

星标: 1

关注者: 3

分支: 0

公开问题: 0

类型:cakephp-plugin

1.0.0-alpha 2016-09-15 00:09 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:03:22 UTC


README

Latest Stable Version Total Downloads License composer.lock

安装

您可以使用 composer 将此插件安装到 CakePHP 应用程序中。

安装 composer 包的推荐方式是

composer require 'nrayann/my-acl:dev-master'

在 app/config/bootstrap.php 中包含 ACL 和 MyAcl 插件

Plugin::load('Acl', ['bootstrap' => true]);
Plugin::load('MyAcl', ['bootstrap' => false, 'routes' => true]);

在 AppController 中包含并配置 AuthComponent 和 AclComponent

public $components = [
    'Acl' => [
        'className' => 'Acl.Acl'
    ]
];
...
$this->loadComponent('Auth', [
    'authorize' => [
        'Acl.Actions' => ['actionPath' => 'controllers/']
    ],
    'loginAction' => [
        'plugin' => false,
        'controller' => 'Users',
        'action' => 'login'
    ],
    'loginRedirect' => [
        'plugin' => false,
        'controller' => 'Pages',
        'action' => 'display'
    ],
    'logoutRedirect' => [
        'plugin' => false,
        'controller' => 'Users',
        'action' => 'login'
    ],
    'unauthorizedRedirect' => [
        'plugin' => false,
        'controller' => 'Users',
        'action' => 'login',
        'prefix' => false
    ],
    'authError' => 'You are not authorized to access that location.',
    'flash' => [
        'element' => 'error'
    ]
]);

添加 UsersController::login 函数

public function login() {
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error(__('Your username or password was incorrect.'));
    }
}

添加 UsersController::logout 函数

public function logout() {
    $this->Flash->success(__('Good-Bye'));
    $this->redirect($this->Auth->logout());
}

添加 src/Templates/Users/login.ctp

<?= $this->Form->create() ?>
<fieldset>
    <legend><?= __('Login') ?></legend>
    <?= $this->Form->input('username') ?>
    <?= $this->Form->input('password') ?>
    <?= $this->Form->submit(__('Login')) ?>
</fieldset>
<?= $this->Form->end() ?>

在 config/app.php 中设置数据库配置

运行 ``` bin/cake migrations migrate -p Acl


Run ```
bin/cake acl_extras aco_sync
``` to automatically create ACOs.

Run ```
bin/cake migrations migrate -p MyAcl
``` to create Users and Groups tables.

Run ```
bin/cake migrations seed --seed UsersSeed -p MyAcl
``` to create the admin user.

Run ```
bin/cake acl grant Groups.1 controllers
``` to grant permissions for admin group.

Inside the project folder, run `sudo chmod -R 777 tmp/` to solve/avoid permission errors.

Log in credentials:
username: you@example.com
password: 123456

For aco sync, access http://"your-application-address"/my-acl/permissions/acoSync

For grant/deny permissions to users and groups, click on permissions buttom at actions column in its index template.

For hide or show ACOS on permission lists, click on config buttom or access http://"your-application-address"/my-acl/permissions/config