oxenti / user
User plugin for CakePHP
Installs: 174
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.4.16
- admad/cakephp-jwt-auth: ^2.0
- cakemanager/cakephp-utils: dev-master#fe519033bc1bbaaa9fa98b9282b47b7938954b2f
- cakephp/cakephp: ~3.0
- oxenti/address: dev-master
- oxenti/soft-delete: dev-master
- ua-parser/uap-php: ^3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2025-01-04 20:14:50 UTC
README
This plugin contains a package with API methods for managing Users on a CakePHP 3 application. This plugin implements Authentication and Authorization tasks.
Requirements
- CakePHP 3.0+
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require oxenti/user
Configuration
In your app's config/bootstrap.php
add:
// In config/bootstrap.php Plugin::load('User');
or using cake's console:
./bin/cake plugin load User
In your app's 'config/app.php' add this to your Datasources array:
'oxenti_user' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'ỳour_db_host', 'username' => 'username', 'password' => 'password', 'database' => 'databse_name', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true, 'log' => false, 'quoteIdentifiers' => false, ], 'test_oxenti_user' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'ỳour_db_host', 'username' => 'username', 'password' => 'password', 'database' => 'databse_name', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true, 'log' => false, 'quoteIdentifiers' => false, ],
In your app's 'AppController.php' set up the Auth componet:
... $this->loadComponent('Auth', [ 'authorize' => ['Controller'], 'authenticate' => [ 'Form' => [ 'userModel' => 'User.Users', 'fields' => [ 'username' => 'email', 'password' => 'password' ] ], 'User.Jwt' => [ 'parameter' => '_token', 'userModel' => 'User.Users', 'scope' => ['Users.is_active' => 1], 'fields' => [ 'id' => 'id' ], ] ], 'storage' => 'Memory', 'unauthorizedRedirect' => false ]); ...
Add the beforeFilter and isAuthorized methods:
public function beforeFilter(Event $event) { $this->Auth->deny(['*']); $this->Auth->allow(['display']); } public function isAuthorized($user) { return false; }
Configuration files
Move the 'user.php' config file from the plugin's config folder to your app's config folder.
On your app's 'bootstrap.php' add the user configuration file:
... try { Configure::config('default', new PhpConfig()); Configure::load('app', 'default', false); } catch (\Exception $e) { die($e->getMessage() . "\n"); } Configure::load('user', 'default'); ...
Using extrenal Associations
If you want to associate the Address table with other tables on your application, use the address.php configuration file setting the 'relations' entry to your needs.