MyAcl plugin for CakePHP
, (*1)
Installation
You can install this plugin into your CakePHP application using composer., (*2)
The recommended way to install composer packages is:, (*3)
composer require 'nrayann/my-acl:dev-master'
Include the ACL and MyAcl plugin in app/config/bootstrap.php, (*4)
Plugin::load('Acl', ['bootstrap' => true]);
Plugin::load('MyAcl', ['bootstrap' => false, 'routes' => true]);
Include and configure the AuthComponent and the AclComponent in the AppController, (*5)
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, (*6)
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, (*7)
public function logout() {
$this->Flash->success(__('Good-Bye'));
$this->redirect($this->Auth->logout());
}
Add src/Templates/Users/login.ctp, (*8)
<?= $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
, (*9)
Run bin/cake migrations migrate -p Acl
to create acl tables., (*10)
Run bin/cake acl_extras aco_sync
to automatically create ACOs., (*11)
Run bin/cake migrations migrate -p MyAcl
to create Users and Groups tables., (*12)
Run bin/cake migrations seed --seed UsersSeed -p MyAcl
to create the admin user., (*13)
Run bin/cake acl grant Groups.1 controllers
to grant permissions for admin group., (*14)
Inside the project folder, run sudo chmod -R 777 tmp/
to solve/avoid permission errors., (*15)
Log in credentials:
username: you@example.com
password: 123456, (*16)
For aco sync, access http://"your-application-address"/my-acl/permissions/acoSync, (*17)
For grant/deny permissions to users and groups, click on permissions buttom at actions column in its index template., (*18)
For hide or show ACOS on permission lists, click on config buttom or access http://"your-application-address"/my-acl/permissions/config, (*19)