Permalink
Browse files

* readme document updated (minor fixes, styling)

  • Loading branch information...
1 parent 593bb24 commit ead9cadce75435a087e303e151c2e833d04b6fca @barbir committed Apr 6, 2012
Showing with 82 additions and 83 deletions.
  1. +82 −83 README.md
View
@@ -10,6 +10,7 @@ Installation
------------------------------------------------------------------------------------------------
First you need to install the plugin like so:
+
* Download the CakePHP Array ACL plugin from github
(http://github.com/barbir/cakephp-array-acl/archives/master)
* Unpack the contents of the archive to the plugins folder of the CakePHP project and rename
@@ -25,66 +26,64 @@ First you need to install the plugin like so:
If you don't have users and groups tables and/or login and logout actions for your users
------------------------------------------------------------------------------------------------
-
If you have users and groups tables compatible with the plugin, skip this part. If you don't,
execute the below scripts to create both tables.
Users:
- create table `users`
- (
- `id` int(10) unsigned not null auto_increment,
- `group_id` int(10) unsigned not null,
- `username` varchar(50) collate utf8_unicode_ci not null,
- `password` varchar(50) collate utf8_unicode_ci not null,
- `name` varchar(255) collate utf8_unicode_ci not null,
- primary key (`id`)
- ) default charset=utf8 collate=utf8_unicode_ci;
+ create table `users`
+ (
+ `id` int(10) unsigned not null auto_increment,
+ `group_id` int(10) unsigned not null,
+ `username` varchar(50) collate utf8_unicode_ci not null,
+ `password` varchar(50) collate utf8_unicode_ci not null,
+ `name` varchar(255) collate utf8_unicode_ci not null,
+ primary key (`id`)
+ ) default charset=utf8 collate=utf8_unicode_ci;
Groups:
- create table `groups`
- (
- `id` int(10) unsigned not null auto_increment,
- `name` varchar(255) collate utf8_unicode_ci not null,
- primary key (`id`)
- ) default charset=utf8 collate=utf8_unicode_ci;
+ create table `groups`
+ (
+ `id` int(10) unsigned not null auto_increment,
+ `name` varchar(255) collate utf8_unicode_ci not null,
+ primary key (`id`)
+ ) default charset=utf8 collate=utf8_unicode_ci;
Now open your CakePHP console, and bake the MVC files for both tables (prefererbly with "some
-basic class methods").
-
-Now when that's freshly baked, add login and logout actions to your controller:
-
- function login($data = null)
- {
- if ($this->Session->read('Auth.User'))
- {
- $this->Session->setFlash(__('You are logged in!', true));
- $this->redirect('/', null, false);
- }
- }
-
- function logout()
- {
- $this->Session->setFlash('Logout message...');
- $this->redirect($this->Auth->logout());
- }
+basic class methods"). When that's freshly baked, add login and logout actions to your controller:
+
+ function login($data = null)
+ {
+ if ($this->Session->read('Auth.User'))
+ {
+ $this->Session->setFlash(__('You are logged in!', true));
+ $this->redirect('/', null, false);
+ }
+ }
+
+ function logout()
+ {
+ $this->Session->setFlash('Logout message...');
+ $this->redirect($this->Auth->logout());
+ }
And create the login view for your users controller (yourapproot/app/views/users/login.ctp):
- <h2>Login</h2>
- <?php
- echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' =>'login')));
- echo $this->Form->input('User.username');
- echo $this->Form->input('User.password');
- echo $this->Form->end('Login');
- ?>
+ <h2>Login</h2>
+ <?php
+ echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' =>'login')));
+ echo $this->Form->input('User.username');
+ echo $this->Form->input('User.password');
+ echo $this->Form->end('Login');
+ ?>
Usage
------------------------------------------------------------------------------------------------
When you install the plugin, you are ready to use it. In order to use the CakePHP Array ACL
plugin, you need to:
+
* include the Array ACL component
* initialize the ACL list object
* execute the ArrayAcl auth
@@ -95,54 +94,54 @@ Include the Array ACL component
Include the Array ACL component in your controller, by adding 'ArrayAcl.ArrayAcl' to your
$components array. Besides this, include the Auth componenet.
- var $components = array(... 'Auth', 'ArrayAcl.ArrayAcl');
+ var $components = array(... 'Auth', 'ArrayAcl.ArrayAcl');
Initialize the ACL list object and the Auth object
--------------------------------------------------
In the app controller's beforeFilter action, add the following code:
- // 1. init the Auth component settings (optional)
- $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
- $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
- $this->Auth->loginRedirect = array('/');
-
- // 2. init the Auth component authorize method (mandatory)
- $this->Auth->authorize = 'controller';
-
- // 3. init the ArrayAcl components ACL array
- $this->ArrayAcl->acl = array
- (
- // everyone
- '*' => array
- (
-
- '*' => 'deny', // deny everything
- 'users/login' => 'allow', // allow login to everyone
- 'pages/*' => 'allow', // allow static pages
- ),
-
- // admins
- '1' => array
- (
-
- '*' => 'allow', // allow everything
- ),
-
- // users
- '2' => array
- (
- '*' => 'allow', // allow everything
-
- // deny users controller, except login, logout
- 'users/*' => 'deny',
- 'users/login' => 'allow',
- 'users/logout' => 'allow',
- )
- );
-
- // 4. execute the ArrayAcl authorize logic
- $this->ArrayAcl->authorize($this);
+ // 1. init the Auth component settings (optional)
+ $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
+ $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
+ $this->Auth->loginRedirect = array('/');
+
+ // 2. init the Auth component authorize method (mandatory)
+ $this->Auth->authorize = 'controller';
+
+ // 3. init the ArrayAcl components ACL array
+ $this->ArrayAcl->acl = array
+ (
+ // everyone
+ '*' => array
+ (
+
+ '*' => 'deny', // deny everything
+ 'users/login' => 'allow', // allow login to everyone
+ 'pages/*' => 'allow', // allow static pages
+ ),
+
+ // admins
+ '1' => array
+ (
+
+ '*' => 'allow', // allow everything
+ ),
+
+ // users
+ '2' => array
+ (
+ '*' => 'allow', // allow everything
+
+ // deny users controller, except login, logout
+ 'users/*' => 'deny',
+ 'users/login' => 'allow',
+ 'users/logout' => 'allow',
+ )
+ );
+
+ // 4. execute the ArrayAcl authorize logic
+ $this->ArrayAcl->authorize($this);
Part "1. init the Auth component settings" is optional and read about the Auth component
in the cookbook if you wish to know more.

0 comments on commit ead9cad

Please sign in to comment.