Implementing extra features for Plugin cake-control for CakePHP 3

Em Português

This is a plugin for access control with good resources for applications with CakePHP 3.

This guide is for the Plugin cake-control in CakePHP 3 found in:

Roadmap for Creating an application with CakePHP 3 Using the Control Component
To serve management section

PostgreSQL and MySQL support

In the docs folder there is a script to create database with tables groups, users, permissions and servidores (for mysql and postgresql) that will be used in the creation of the administration section. When you create another application, you can use the script below and create their own tables in place of these, as well as generate their own code using Bake or from scratch.
Remember to keep the tables groups, users and permissions, they are the basis of Control Component.

The database script's comes with records in the tables groups and servidores. Servidores is only a teaching demonstration table, not the one we use on our intranet is just to demonstrate how we can create our own.

The records of the users table are registered manually, each through the web application.

The records of permissions table are registered by the application automatically through the component call in AppController.php, only the first login. After the first login we can even comment on the respective lines.

Roadmap for application creation with Access Control

Consider that I am creating an application called the cakecontrol1 (change the will)

I will assume that you have already created the application, installed the plugin and made other basic settings in the article:

1) To type dates Formatting Brazilian and bake generating uses to login and logout. To others languages dont use the config/bootstrap.php on docs..

Download the plugin

Unzip and go to the docs folder. Then do the following copy:

bootstrap.php for cakecontrol1/config (use only for other kanguages than en_US)
bootstrap_cli.php for cakecontrol1/config
AppController.php to cakecontrol1/src/ Controller
ControlComponent.php to cakecontrol1src/Controller/Component

Remember to reconfigure the AppController.php by inserting the helper and the layout (as stated in the first article) and also load the plugin in bootstrap.php.

2) Regenerate the CRUDs but now supports the Brazilian formatting dates and generating login and logout
Prior notice now appear as fields like date and datatime and look after re-generate the code.

cd cakecontrol1

bin/cake bake all groups --theme CakeControl --force
bin/cake bake all users --theme CakeControl --force
bin/cake bake all permissions --theme CakeControl --force
bin/cake bake all servers --theme CakeControl --force

Visit the Web, or better, just hit F5 to refresh.

See now it requests password, as well as the menu does not show the links.

Customizing the less

The following procedures are already implemented. Your menu should now appear with white links, but reported if you want to customize something.

We need to change the color of links (the anchor), overwriting the bootstrap behavior:

Checking with the browser inspector, I realized I need to change the anchor of color btn-primary class.

But it is best not to change it, for I will be changing other areas. Ideally we will create another class just adding to and inheriting from btn-primary.

Then edit the script:


Just below the class

.btn-primary {

I created this:

.btn-primary to {
  color: #fff;

We will allow access for now:

Uncomment the line 64 src/AppController.php

3) Register users to implement Access Control
3.1) Access the web by application

to register four users, one each group


Use to test password the same as the login, so

Password  User         Group

Supers       user           super
Admins      admin       admin
Managers manager  manager
Users         user          user

When enrolling see if encryption is being applied, appearing in the Users / index the encrypted password, rather than plain text.
It is interesting to remove the password index.ctp field.

Now we have 4 groups:

Supers - full power, access all application
Adminsl -Access to administrative tables: groups, users and permissions
Managers - access all Admins do not access: all the different tables of groups, users and permissions, if servers
Users - initially have access only to login and logout. So you can access any other action needs to be registered in their actions.

3.2) Testing Application

Remove Element topmenu-in vendor/ribafs/cake-control/src/Template/Layout/default.ctp. Just comment the line 74.

Review again to 64 of cakecontrol1 line /src/AppController.php and save

Now press F5 in the browser that it will ask the login and password.

Try as access
user and user

It accesses, so that shows "Logged in as User" and the Exit button, but receive a
error message for not having access to servers / index.

The component automatically populates permissions table, but only for supers,
admins and managers. Nothing to users


3.3) Granting Permission

Let's give the user access only to the user controller servers and index action ().

Access the Web

(Log in as super or admin. Both have full access permission on Permissions)

And add a new Permissions Group to the "Users" access controller servers, index action:

Group - Users
Controller - Servers
Action - index

Obs .: we should ideally create two combos for Permissions / add.ctp, one for
controller and one for action.

Click Exit

- Log in now with the user "user" and password "user":


Try to access any other action other than index. You will be denied access.
Delete only because there is a bug in the component. Show a way to solve the item 16.

3.4) Tip
Remove the label and the value of the password field Template / Users / index
Proceed similarly for tables with many fields, leave only the most important in index.ctp.
Remember that doing this will only show some fields on the screen.

4) Implement search

The most practical example is the servers, which is almost ready.

Edit the controller and uncomment the index action () Servers controller and comment or remove the index action () existing.
If you want to implement to another controller make the appropriate changes to both the controller as the fields.

Then go to the Template index.ctp/Servidores and uncomment the search code, early in the index.ctp.

5) Customization of labels

Already implemented, see Template in Users/login.ctp

6) Validations

In cpf, cnpj, phone, email, date, zip code, null, not null, login (nome.sobrenome)
Only a few have been implemented. See the file docs/ValidacoesDicas.txt:

7) displayField ()
See that Servidores/index shows the users of ID but we will change this so that
appear the username instead of the ID. Here's how the file docs/displayField.txt:

Remove the caption and the password value in Template / Users / index.ctp

8) Cloning cakecontrol1

Depending on how it is configured your server, after cloning this application creating a new copy, then you need to re-adjust the permissiões file system, specifically the / tmp and / logs.

Deploying the Application aInternacionalização

Follow the steps in this article:

Suggested Administrative Area Centralized

An area with a menu that calls each of the applications and when you exit the application back to the menu. The cakecontrol1 application will be cloned by creating each of the new applications that compose the intranet.

Obs .: before cloning applications to create new applications, remember to remove the table servers along with all your code and just enjoy the rest.

In /var/www/html have:

/ intranet
application 1
application 2
application 3

In the application change in the initialize the AppController logoutRedirect for:

'LogoutRedirect' => [
'Controller' => 'index.html'
'Action' => false

The index.html may well be replaced by a new menu in the internal portal in Joomla.
The CMS will have an Intranet menu with menu items for each application.

So when you click Application 1 Application1 will be called and when you click Exit on Application1 back to the Intranet menu in the CMS.

Ribamar FS, Fortaleza - Brazil, 17/09/2016