josegonzalez/cakephp-users

CakePHP的用户插件

安装: 59

依赖: 1

建议者: 0

安全: 0

星级: 1

关注者: 3

分支: 0

开放问题: 0

类型:cakephp-plugin

0.1.2 2019-11-30 21:53 UTC

This package is auto-updated.

Last update: 2024-08-29 04:48:44 UTC


README

为您的CRUD启用应用程序提供用户身份验证和管理。

安装

您可以使用composer将此插件安装到您的CakePHP应用程序中。

安装composer包的推荐方法是

composer require josegonzalez/cakephp-users

使用方法

加载插件

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

使用以下类似的迁移创建users

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

如果启用密码重置,您还需要加载Muffin/Tokenize插件并运行其迁移

bin/cake plugin load Muffin/Tokenize --routes

bin/cake migrations migrate --plugin Muffin/Tokenize

如果启用社交身份验证,您还需要加载ADmad/SocialAuth插件并运行其迁移

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

bin/cake migrations migrate -p ADmad/SocialAuth

并将AuthTrait添加到您的AppController

namespace App\Controller;

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

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

配置

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'
                        ]
                    ],
                ],
            ],
        ],
    ],
];