All Projects → UseMuffin → Footprint

UseMuffin / Footprint

Licence: mit
CakePHP plugin to allow passing currently logged in user to model layer.

Projects that are alternatives of or similar to Footprint

Cakephp Tools
A CakePHP Tools plugin containing lots of useful helpers, behaviors, components, shells, ...
Stars: ✭ 325 (+301.23%)
Mutual labels:  cakephp, cakephp-plugin
Aclmanager
Plugin to manage Acl for CakePHP 2.x
Stars: ✭ 59 (-27.16%)
Mutual labels:  cakephp, cakephp-plugin
crud-view
CakePHP: Automated admin backend based on your CRUD configuration
Stars: ✭ 45 (-44.44%)
Mutual labels:  cakephp, cakephp-plugin
Cakepdf
CakePHP plugin for creating and/or rendering PDFs, supporting several popular PDF engines.
Stars: ✭ 360 (+344.44%)
Mutual labels:  cakephp, cakephp-plugin
Bootstrap Ui
CakePHP: Transparently use Bootstrap
Stars: ✭ 293 (+261.73%)
Mutual labels:  cakephp, cakephp-plugin
Slug
Slugging for CakePHP
Stars: ✭ 32 (-60.49%)
Mutual labels:  cakephp, cakephp-plugin
Debug kit
Debug Toolbar for CakePHP applications.
Stars: ✭ 858 (+959.26%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-api-pagination
📑 CakePHP 4 plugin that injects pagination information into API responses.
Stars: ✭ 39 (-51.85%)
Mutual labels:  cakephp, cakephp-plugin
Enum
Enumeration list for CakePHP 3
Stars: ✭ 27 (-66.67%)
Mutual labels:  cakephp, cakephp-plugin
crud-users
CakePHP: Users plugin based on the CRUD action classes
Stars: ✭ 17 (-79.01%)
Mutual labels:  cakephp, cakephp-plugin
Asset compress
An asset compression plugin for CakePHP. Provides file concatenation and a flexible filter system for preprocessing and minification.
Stars: ✭ 370 (+356.79%)
Mutual labels:  cakephp, cakephp-plugin
Authorization
PSR7 Middleware for authorization
Stars: ✭ 50 (-38.27%)
Mutual labels:  cakephp, cakephp-plugin
Flypie
Flysystem plugin for CakePHP
Stars: ✭ 35 (-56.79%)
Mutual labels:  cakephp, cakephp-plugin
Crud
Production-grade rapid controller development with built in love for API and Search
Stars: ✭ 339 (+318.52%)
Mutual labels:  cakephp, cakephp-plugin
mixerapi
A CakePHP Plugin for RESTful API Development [READ-ONLY]
Stars: ✭ 26 (-67.9%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-rest
CakePHP REST Plugin - Easily build REST API endpoints in your CakePHP application.
Stars: ✭ 23 (-71.6%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-sequence
CakePHP plugin for maintaining a contiguous sequence of records
Stars: ✭ 41 (-49.38%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-mailgun
Mailgun plugin for CakePHP 3
Stars: ✭ 23 (-71.6%)
Mutual labels:  cakephp, cakephp-plugin
queue
A queue-interop compatible Queueing library
Stars: ✭ 25 (-69.14%)
Mutual labels:  cakephp, cakephp-plugin
Webservice
Bringing the power of the CakePHP ORM to your favourite webservices
Stars: ✭ 79 (-2.47%)
Mutual labels:  cakephp, cakephp-plugin

Footprint

Build Status Coverage Total Downloads License

This plugin allows you to pass the currently logged in user info to the model layer of a CakePHP application.

It comes bundled with the FootprintBehavior to allow you control over columns such as user_id, created_by, company_id similar to the core's TimestampBehavior.

Install

Using Composer:

composer require muffin/footprint

You then need to load the plugin by running console command:

bin/cake plugin load Muffin/Footprint

Usage

Trait

First, you will need to include the Muffin\Footprint\Auth\FootprintAwareTrait to your AppController:

use Muffin\Footprint\Auth\FootprintAwareTrait;

class AppController extends Controller
{
    use FootprintAwareTrait;

    // Specify the user model if required. Defaults to "Users".
    $this->_userModel = 'YourPlugin.Members';
}

This will attach the Muffin\Footprint\Event\FootprintListener to models which will inject the currently logged in user's instance on Model.beforeSave and Model.beforeFind in the _footprint key of $options.

Your controller needs to have either cakephp/authentication plugin's AuthenticationComponent or CakePHP core's deprecated AuthComponent loaded so that the user identity can be fetched.

Behavior

To use the included behavior to automatically update the created_by and modified_by fields of a record for example, add the following to your table's initialize() method:

$this->addBehavior('Muffin/Footprint.Footprint');

You can customize that like so:

$this->addBehavior('Muffin/Footprint.Footprint', [
    'events' => [
        'Model.beforeSave' => [
        	'user_id' => 'new',
            'company_id' => 'new',
            'modified_by' => 'always'
        ]
    ],
    'propertiesMap' => [
        'company_id' => '_footprint.company.id',
    ],
]);

This will insert the currently logged in user's primary key in user_id and modified_by fields when creating a record, on the modified_by field again when updating the record and it will use the associated user record's company id in the company_id field when creating a record.

Warning

If you have the FootprintBehavior attached to a model do not load the model inside Controller::initialize() method directly or indirectly. If you do so the footprint (user entity) won't be set for the model and the behavior won't work as expected. You can load your model in Controller::beforeFilter() if needed.

This is because the FootprintListener which sets the user entity to the models is attached after Controller::initialize() is run.

Patches & Features

  • Fork
  • Mod, fix
  • Test - this is important, so it's not unintentionally broken
  • Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
  • Pull request - bonus point for topic branches

Bugs & Feedback

http://github.com/usemuffin/footprint/issues

License

Copyright (c) 2015-Present, Use Muffin and licensed under The MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].