0

当我尝试实现自定义登录组件时,x 给我一个错误“找不到身份验证适配器“xmlRpc””。

在我的 AppController.php 我有以下

<?php

App::uses('Controller', 'Controller');

//Custom Auth
App::uses('xmlRpc', 'Controller/Component/Auth');

class AppController extends Controller {

    //Authentication component

    public $components = array(
        'Session',
        'DebugKit.Toolbar',
        'Auth' => array(
            'authenticate' => array(
                    'xmlRpc'
                )           
            )
        );

}

然后我的登录组件位于 /Controller/Component/Auth/xmlRpc.php

<?php

App::uses('BaseAuthenticate', 'Controller/Component/Auth');

class xmlRpc extends BaseAuthenticate {

    public function authenticate(CakeRequest $request, CakeResponse $response) {
        return true;
    }
}
?>

在我的用户控制器中,我有以下内容:

<?php
App::uses('AppController', 'Controller');

//Custom Auth
App::uses('xmlRpc', 'Controller/Component/Auth');

class UsersController extends AppController {

    public function logout() {
        return $this->redirect($this->Auth->logout());
    }   

    public function login() {

        if ($this->request->is('post')) {

            if ($this->Auth->login()) {

                return $this->redirect($this->Auth->redirectUrl());
                // Prior to 2.3 use `return $this->redirect($this->Auth->redirect());`

            } else {

                $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
            }
        }
    }

}
?>

顺便说一句,在我的身份验证函数中,我总是返回 true 来进行测试。一旦我摆脱了这个错误,就会添加逻辑。请协助并放轻松,因为我是Cake n00b。如何获得蛋糕以查看我的自定义身份验证适配器?

4

3 回答 3

1

遵循 CakePHP 的命名约定,类应该命名XmlRpcAuthenticate,文件也是(.php当然有扩展名)。在App::uses()调用和配置中使用不带 的名称Authenticate,即XmlRpc

// This App::uses()  call is actually not necessary in the controller unless
// your are actually trying to access the class directly
App::uses('XmlRpc', 'Controller/Component/Auth');

...

public $components = array(
    ...

    'Auth' => array(
        'authenticate' => array(
             'XmlRpc'
        )           
    )
);

另请参阅http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authentication-objects

于 2013-10-08T13:28:21.350 回答
0

我认为您的身份验证适配器的正确名称应该是 xmlRpcAuthenticate

class xmlRpcAuthenticate extends BaseAuthenticate {
于 2013-10-08T13:28:03.070 回答
0

只需将您的函数的首字母大写,我也以这种方式解决了它..谢谢

于 2014-11-05T07:07:28.053 回答