oxenti/user

该软件包最新版本(dev-master)没有可用的许可证信息。

CakePHP 的用户插件

维护者

详细信息

github.com/oxenti/User

源代码

问题

安装: 174

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 8

分支: 0

公开问题: 0

类型:cakephp-plugin

dev-master 2016-09-01 14:17 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:52:49 UTC


README

此插件包含一个包含管理 CakePHP 3 应用程序中用户 API 方法的软件包。此插件实现身份验证和授权任务。

需求

  • CakePHP 3.0+

安装

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

安装 composer 软件包的推荐方法是

composer require oxenti/user

配置

在您的应用程序的 config/bootstrap.php 中添加

// In config/bootstrap.php
Plugin::load('User');

或使用 cake 的控制台

./bin/cake plugin load User

在您的应用程序的 'config/app.php' 中将此添加到您的数据源数组中

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

在您的应用程序的 'AppController.php' 中设置 Auth 组件

    ...
    $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
    ]);
    ...

添加 beforeFilter 和 isAuthorized 方法

    public function beforeFilter(Event $event)
    {
        $this->Auth->deny(['*']);
        $this->Auth->allow(['display']);
    }

    public function isAuthorized($user)
    {
        return false;
    }

配置文件

将插件配置文件夹中的 'user.php' 配置文件移动到您的应用程序配置文件夹。

在您的应用程序的 'bootstrap.php' 中添加用户配置文件

    ...
    try {
        Configure::config('default', new PhpConfig());
        Configure::load('app', 'default', false);
    } catch (\Exception $e) {
        die($e->getMessage() . "\n");
    }

    Configure::load('user', 'default');
    ...

使用外部关联

如果您想将地址表与您的应用程序中的其他表关联起来,请使用 address.php 配置文件,设置 'relations' 条目以满足您的需求。