josegonzalez / cakephp-users
CakePHP的用户插件
0.1.2
2019-11-30 21:53 UTC
Requires
- php: >=5.6
- admad/cakephp-social-auth: 0.6.*
- cakephp/cakephp: >=3.5.0 <4.0.0
- friendsofcake/crud: 5.*
- friendsofcake/crud-users: 0.*
- josegonzalez/cakephp-upload: 4.*
- muffin/tokenize: 1.1.*
Requires (Dev)
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' ] ], ], ], ], ], ];