2012-04-12 22 views
0

类我使用的食谱使用下面的代码来创建自己的自定义验证:CakePHP的2.1 - > CustomAuthorization不能正常工作

// Controller/Auth/CustomAuthenticate.php 



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

class CustomAuthenticate extends BaseAuthenticate { 

    public function authenticate(CakeRequest $request, CakeResponse $response) { 
     return false; 
    } 
} 

// Controller/UserController.php 


class UserController extends AppController { 
    var $components = array('Auth' => array('authenticate' => array('Custom'))); 

    public function login() { 
     // some code that includes: 
     $this->Auth->login($this->request->data); 
    } 
} 
用正确的凭据

不知何故,登录似乎工作,虽然身份验证方法在我的CustomAuthentication类中返回false。

我使用CakePHP 2.1

+0

可能是因为这就是你所有的'authenticate()'方法......是返回false。 – 2012-04-12 12:05:19

回答

1

,你不能指望这个工作属性格式,因为你不应该通过$this->request->data上的登录表单。

它只是

$this->Auth->login(); 

否则你跳过验证和传递的数据将随时登录该用户。不管是garbige或正确的凭据。永远不要使用登录表单来做这件事。

+0

这不是真的......除此之外,它不回答我的问题。 – 2012-04-12 13:34:41

+0

你确实有2.x,不是吗?你刚刚指出的同样的链接指出,你站在更正的位置:“在2.0 $ this-> Auth-> login($ this-> request-> data)将登录用户的任何数据张贴”=>那就是我所说。这也是您的代码如此行事的答案。您正在使用强制登录来跳过authenticate()方法。不过,您可能会将验证与授权混淆。 – mark 2012-04-12 13:43:53

+0

对不起,你是对的!这是自1.3以来的一次重大变革,给了我一个很头疼的问题。谢谢! – 2012-04-12 15:38:12