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?
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'
)
)
);
I think the right name for your Authentication adapter should be xmlRpcAuthenticate
class xmlRpcAuthenticate extends BaseAuthenticate {
just make first letter capital of your function, i also solved it this way.. Thanks