https://github.com/maymeow/cakephp-identity
🗝 CakePHP plugin to manage roles and permissions.
https://github.com/maymeow/cakephp-identity
authorization cakephp cakephp-plugin security
Last synced: 11 months ago
JSON representation
🗝 CakePHP plugin to manage roles and permissions.
- Host: GitHub
- URL: https://github.com/maymeow/cakephp-identity
- Owner: MayMeow
- License: mit
- Created: 2020-06-02T07:44:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-02T16:12:53.000Z (about 6 years ago)
- Last Synced: 2024-12-28T01:42:06.293Z (over 1 year ago)
- Topics: authorization, cakephp, cakephp-plugin, security
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CakephpIdentity plugin for CakePHP
Manage roles and permissions for CakePHP.
## Requirements
* CakePHP 4.*
* PHP >= 7.3
* Database (Mysql/MariaDB/Postgres)
* Existing Users table where are stored users data used for authentication.
If you do not have users table you can create new migration and update `change()` function to look like this
```php
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function change()
{
$table = $this->table('users');
$table->addColumn('email', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('password', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->create();
}
```
or use `cake`
```bash
php bin/cake.php bake migration CreateUsers email:string password:string created modified
```
## Installation
You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).
The recommended way to install composer packages is:
```bash
composer require maymeow/cakephp-identity
```
And run
```
php bin/cake.php migrations migrate -p CakephpIdentity
```
this will create following database tables.
|Table name | Description |
|---|---|
| identity_roles | Storing roles information - it's using to group permissions together|
| identity_permissions | Storing permissions information |
| identity_permission_roles | Binding permissions to roles |
| identity_roles_users | Binding users to roles, one user can have multiple roles |
## How to use
Permissions are using action strings to verify permissions. Action string looks like this
`Plugin:/prefix/Controller/Action` or `__:/prefix/Controller/Action` when plugin is not available;
You can get action string via `CakephpIdentity\Factories\ActionFactory::getActionString($this->request)` from any controller;