首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CakeDC用户似乎无法加载自定义控制器

CakeDC用户似乎无法加载自定义控制器
EN

Stack Overflow用户
提问于 2020-10-08 09:01:17
回答 1查看 294关注 0票数 0

我在CakePHP3.8.13、CakeDC用户8.5.1和PHP7.4上运行了一个CakeDC应用程序。我试图使用自定义控制器,以便可以调整LoginTrait和PasswordChangeTrait的行为。

我一直在跟踪https://github.com/CakeDC/users/blob/master/Docs/Documentation/Configuration.md#using-the-users-email-to-login中的文档

但是,我的自定义UsersController并没有被使用。

我在/config/bootstrap.php中添加了以下几行

代码语言:javascript
复制
Configure::write('Users.config', ['users']);
Plugin::load('CakeDC/Users', ['routes' => true, 'bootstrap' => true]);

我创建了一个新文件/config/users.php

代码语言:javascript
复制
<?php

$config = [
    'Users' => [
        // Table used to manage users
        'table' => 'SomethingThatDoesNotExist',
        // Controller used to manage users plugin features & actions
        'controller' => 'MyUsers',
        // configure Auth component
        'auth' => true,
        // Password Hasher
        'passwordHasher' => '\Cake\Auth\DefaultPasswordHasher',
        // token expiration, 1 hour
        'Token' => ['expiration' => 3600],
        'Email' => [
            // determines if the user should include email
            'required' => true,
            // determines if registration workflow includes email validation
            'validate' => true,
        ],
        'Registration' => [
            // determines if the register is enabled
            'active' => false,
            // determines if the reCaptcha is enabled for registration
            'reCaptcha' => true,
            // allow a logged in user to access the registration form
            'allowLoggedIn' => false,
            //ensure user is active (confirmed email) to reset his password
            'ensureActive' => false,
            // default role name used in registration
            'defaultRole' => 'user',
        ],
        'reCaptcha' => [
            // reCaptcha key goes here
            'key' => null,
            // reCaptcha secret
            'secret' => null,
            // use reCaptcha in registration
            'registration' => false,
            // use reCaptcha in login, valid values are false, true
            'login' => false,
        ],
        'Tos' => [
            // determines if the user should include tos accepted
            'required' => true,
        ],
        'Social' => [
            // enable social login
            'login' => false,
            // enable social login
            'authenticator' => 'CakeDC/Users.Social',
        ],
        'GoogleAuthenticator' => [
            // enable Google Authenticator
            'login' => false,
            'issuer' => null,
            // The number of digits the resulting codes will be
            'digits' => 6,
            // The number of seconds a code will be valid
            'period' => 30,
            // The algorithm used
            'algorithm' => 'sha1',
            // QR-code provider (more on this later)
            'qrcodeprovider' => null,
            // Random Number Generator provider (more on this later)
            'rngprovider' => null
        ],
        'Profile' => [
            // Allow view other users profiles
            'viewOthers' => true,
            'route' => ['prefix' => false, 'plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile'],
        ],
        'Key' => [
            'Session' => [
                // session key to store the social auth data
                'social' => 'Users.social',
                // userId key used in reset password workflow
                'resetPasswordUserId' => 'Users.resetPasswordUserId',
            ],
            // form key to store the social auth data
            'Form' => [
                'social' => 'social'
            ],
            'Data' => [
                // data key to store the users email
                'email' => 'email',
                // data key to store email coming from social networks
                'socialEmail' => 'info.email',
                // data key to check if the remember me option is enabled
                'rememberMe' => 'remember_me',
            ],
        ],
        // Avatar placeholder
        'Avatar' => ['placeholder' => 'CakeDC/Users.avatar_placeholder.png'],
        'RememberMe' => [
            // configure Remember Me component
            'active' => false,
            'checked' => true,
            'Cookie' => [
                'name' => 'remember_me',
                'Config' => [
                    'expires' => '1 month',
                    'httpOnly' => true,
                ]
            ]
        ],
        'Superuser' => ['allowedToChangePasswords' => true], 
    ],
    'GoogleAuthenticator' => [
        'checker' => \CakeDC\Users\Auth\DefaultTwoFactorAuthenticationChecker::class,
        'verifyAction' => [
            'plugin' => 'CakeDC/Users',
            'controller' => 'Users',
            'action' => 'verify',
            'prefix' => false,
        ],
    ],
    'U2f' => [
        'enabled' => false,
        'checker' => \CakeDC\Users\Auth\DefaultU2fAuthenticationChecker::class,
        'startAction' => [
            'plugin' => 'CakeDC/Users',
            'controller' => 'Users',
            'action' => 'u2f',
            'prefix' => false,
        ]
    ],
    
];

return $config;

注意,指定的表名不是真实的类名,也不存在。应用程序继续运行,没有问题。如果我将配置更改为:

代码语言:javascript
复制
$config = [
    'Users' => [
        // Table used to manage users
        'table' => '\SomethingThatDoesNotExist',
...

也就是说,只需将反斜杠添加到我收到的错误表名中即可。

代码语言:javascript
复制
Class '\SomethingThatDoesNotExist' not found. Error in: ROOT\vendor\cakephp\cakephp\src\ORM\Locator\TableLocator.php, line 239

我实际上不需要自定义表,我想定制控制器,但无论我输入什么控制器配置,我没有收到任何错误!我在下面的路径/src/Controller/MyUsersController.php,中有一个有效的控制器,但是下面的任何配置都不会触发它的使用:

代码语言:javascript
复制
'controller' => 'MyUsers',
'controller' => '\MyUsers',
'controller' => 'App\Controller\MyUsers',
'controller' => '\App\Controller\MyUsers',

如何让我的自定义控制器加载?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-12 07:41:32

自定义控制器似乎并不覆盖它仅根据自定义控制器名称覆盖的当前路由,即不是/login,而是/myuser/登录。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64259150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档