Skip to content

A simple wrapper for various projects to make crud and user management a breeze

License

Notifications You must be signed in to change notification settings

josegonzalez/cakephp-users

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Users plugin for CakePHP

Provides user authentication and administration for your CRUD-enabled application.

Installation

You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require josegonzalez/cakephp-users

Usage

Load the plugin

Plugin::load('Users', ['bootstrap' => true, 'routes' => true]);

Create the users table with a migration similar to the following:

bin/cake bake migration create_users verified:boolean active:boolean email:string:unique:U_email password avatar avatar_dir created modified

If enabling password resets, you will also need to load the Muffin/Tokenize plugin and run it's migrations:

bin/cake plugin load Muffin/Tokenize --routes

bin/cake migrations migrate --plugin Muffin/Tokenize

If enablign social authenticationn, you will also need to load the ADmad/SocialAuth pluginn and run it's migrations:

bin/cake plugin load ADmad/SocialAuth -b -r

bin/cake migrations migrate -p ADmad/SocialAuth

And add the AuthTrait to your AppController:

namespace App\Controller;

use Cake\Controller\Controller;
use Users\Controller\AuthTrait;

class AppController extends Controller
{
    use AuthTrait;
    public function initialize()
    {
        $this->loadAuthComponent();
    }
}

Configuration

return [
    'Users' => [
        // Name of the table to use
        'userModel' => 'Users.Users',

        // Enable users the ability to upload avatars
        'enableAvatarUploads' => true,

        // Enable the password-reset flow
        'enablePasswordReset' => true,

        // Require that a user's email be authenticated
        'requireEmailAuthentication' => true,

        // Make all users active immediately
        'setActiveOnCreation' => true,

        // Fields to use for authentication
        'fields' => [
            'username' => 'email',
            'password' => 'password',
        ],

        // SocialAuth plugin configuration
        'social' => [
            'getUserCallback' => 'getUserFromSocialProfile',
            'serviceConfig' => [
                'provider' => [
                    'facebook' => [
                        'applicationId' => '<application id>',
                        'applicationSecret' => '<application secret>',
                        'scope' => [
                            'email'
                        ]
                    ],
                ],
            ],
        ],
    ],
];

About

A simple wrapper for various projects to make crud and user management a breeze

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages