nrayann/my-acl

CakePHP plugin for manage ACL with a friendly interface.

Installs: 34

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:cakephp-plugin

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

This package is not auto-updated.

Last update: 2024-04-22 10:49:04 UTC


README

Latest Stable Version Total Downloads License composer.lock

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

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

Include the ACL and MyAcl plugin in app/config/bootstrap.php

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

Include and configure the AuthComponent and the AclComponent in the AppController

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'
    ]
]);

Add UsersController::login function

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.'));
    }
}

Add UsersController::logout function

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

Add 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() ?>

Set up your database config in config/app.php

Run ``` 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