2017 © Pedro Peláez
 

cakephp-plugin users-permissions

Users Permissions Management plugin for CakePHP with GUI

image

hassnainabass/users-permissions

Users Permissions Management plugin for CakePHP with GUI

  • Wednesday, June 7, 2017
  • by hussnain.abass
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

UsersPermissions plugin for CakePHP

The UsersPermissions plugin is for allowing admins to add user permissions for each module in Cakephp. It provides a basic interface to manage user permissions and check upon each request. It provides check box based user permissions in a form like magento. The plugin uses bootstrap by default but you can change that. It will automatically get all controllers and actions from Your Cakephp application and in a GUI you can select the permissions for all controller or actions inside a controller., (*1)

Image of UsersPermissions, (*2)

Requirements

Installation

You can install this plugin into your CakePHP 3 application using composer., (*3)

The recommended way to install composer packages is:, (*4)

composer require  "hassnainabass/users-permissions:*"

Or download the files and move to root/plugins and paste it there, Please rename the folder to UsersPermissions, (*5)

After successfull steps above, Please follow the following:

  • Load Plugin in config/bootstrap.php Plugin::load('UsersPermissions', ['routes' => true]);
  • Open console/terminal and run the following migration,please make sure to load migration plugin first, (*6)

    bin/cake migrations migrate -p UsersPermissions
    

    Or create the following table in database:, (*7)

    CREATE TABLE user_permissions (
      id int(11) NOT NULL AUTO_INCREMENT,
      user_id int(11) DEFAULT NULL,
      permissions text DEFAULT NULL,
      created_on timestamp NULL DEFAULT CURRENT_TIMESTAMP,
      updated_on date DEFAULT NULL,
      PRIMARY KEY (id)
    )
    ENGINE = INNODB
    AUTO_INCREMENT = 1
    CHARACTER SET latin1
    COLLATE latin1_swedish_ci;
    

    It will create a table named "user_permissions" in database using default database connection configured in config/app.php of your cakephp installation., (*8)

  • Change the route for your plugin GUI in plugins/UserPermissions/config/routes.php , By default it is domain.com/users-permissions, (*9)

    Router::plugin(
        'UsersPermissions',
        ['path' => '/users-permissions'],
        function ($routes) {
            $routes->fallbacks('DashedRoute');
        }
    );
    
  • Update call back url if user does not have permision for a particular action. To update the url, replace 'dashboard' in plugins/UsersPermissions/src/controller/component/ResourceComponent.php return $this->_registry->getController()->redirect('/dashboard');
  • Update composer, Go to the root directory for your cakephp installation and run the following command: composer dumpautoload

Thats all your plugin has been installed, yay :), (*10)

You can access the GUI if you have 'admin' role in Users table in user authentication and authorization of cakephp application., (*11)

Usage

  • If you want to load the plugin and permissions for all actions of all controllers and routes. Add the following code in cakephpapp/src/controller/AppController.php, (*12)

    public function initialize()
    {
        parent::initialize();
        // Some code
        // Load Resource Component
        $this->loadComponent('UsersPermissions.Resource');
    }
    
    public function beforeFilter(Event $event)
    {
        parent::beforeFilter($event);
        // Some code
        // Load permissions check function from Resource component
        $this->Resource->checkPermision();
    }
    
    
  • If you want to load the plugin and permissions for all actions of only one controllers. Add the following code in desired controller (same as above) cakephpapp/src/controller/ExampleController.php, (*13)

    public function initialize()
    {
        parent::initialize();
        // Some code
        // Load Resource Component
        $this->loadComponent('UsersPermissions.Resource');
    }
    
    public function beforeFilter(Event $event)
    {
        parent::beforeFilter($event);
        // Some code
        // Load permissions check function from Resource component
        $this->Resource->checkPermision();
    }
    
    
  • If you want to load the plugin and permissions for only one actions of only one controllers. Add the following code in desired controller and in the start of desired action/function in cakephpapp/src/controller/ExampleController.php, (*14)

    public function initialize()
    {
        parent::initialize();
        // Some code
        // Load Resource Component
        $this->loadComponent('UsersPermissions.Resource');
    }
    
    public function exampleAction($param = null)
    {
        // Load permissions check function from Resource component
        $this->Resource->checkPermision();
    
        // Some code
    
    }
    
    

    *The plugin uses bootstrap as front-end styling but you can update the views. To do that you can update the following files., (*15)

    plugins/UsersPermissions/src/template/Permissions/index.ctp plugins/UsersPermissions/src/template/Permissions/userpermission.ctp, (*16)

Author

Developed by Hassnain Abass - Senior Web Developer and Freelancer, (*17)

Contributing

This repository follows the CakePhp Plugin Standards. If you'd like to contribute new features, enhancements or bug fixes to the plugin, please feel free to pull or report/open issues., (*18)

License

Copyright 2017-2020 Hassnain Abass. All rights reserved., (*19)

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file., (*20)

Goodluck And Happy Coding., (*21)

The Versions

07/06 2017

dev-master

9999999-dev

Users Permissions Management plugin for CakePHP with GUI

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Hassnain Abass

cakephp users user permissions