dongping4901 2013-10-08 13:21
浏览 25
已采纳

Cakephp错误:找不到身份验证适配器“xmlRpc”

x gives me an error "Authentication adapter "xmlRpc" was not found" when I try implement a custom login component.

In my AppController.php I have the following

<?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'
                )           
            )
        );

}

Then I have my login compononent located in /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;
    }
}
?>

In my users controller I have the following:

<?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');
            }
        }
    }

}
?>

By the way in my authenticate function I always return true just for testing. Will add logic once I get rid of this error. Please assist and take it easy on me because im a Cake n00b. How to I get cake to see my custom authentication adapter?

  • 写回答

3条回答 默认 最新

  • doudao1369 2013-10-08 13:28
    关注

    Follow the CakePHP naming conventions, the class should be named XmlRpcAuthenticate, the file too (with .php extension of course). In the App::uses() call and in the configuration use the name without Authenticate, ie 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'
            )           
        )
    );
    

    See also http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authentication-objects

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)