当我尝试登录时,请求被Security
组件黑洞。我怎样才能让它正常工作?
我有一个简单的登录表单
<div class="container container-login">
<h2><?php echo __('Login'); ?></h2>
<div class="wrap-form-signin">
<?php
echo $this->Form->create('User', array('action' => 'login', 'class' => 'form-signin'));
echo $this->Form->input('username', array('label' => '', 'placeholder' => __('Email')));
echo $this->Form->input('password', array('label' => '', 'placeholder' => __('Password')));
echo $this->Form->submit(__('Login'));
echo $this->Form->end();
?>
</div>
</div>
控制器动作如下:
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
}
}
}
并且该Security
组件包含在AppController
public $components = array('Security', ... );
在error.log中我得到:
2013-03-29 13:40:58 Error: [BadRequestException] The request has been black-holed
Request URL: /users/login
Stack Trace:
#0 C:\wamp\www\cdx\lib\Cake\Controller\Component\SecurityComponent.php(234): SecurityComponent->blackHole(Object(UsersController), 'auth')
#1 [internal function]: SecurityComponent->startup(Object(UsersController))
#2 C:\wamp\www\cdx\lib\Cake\Utility\ObjectCollection.php(131): call_user_func_array(Array, Array)
#3 [internal function]: ObjectCollection->trigger(Object(CakeEvent))
#4 C:\wamp\www\cdx\lib\Cake\Event\CakeEventManager.php(247): call_user_func(Array, Object(CakeEvent))
#5 C:\wamp\www\cdx\lib\Cake\Controller\Controller.php(670): CakeEventManager->dispatch(Object(CakeEvent))
#6 C:\wamp\www\cdx\lib\Cake\Routing\Dispatcher.php(183): Controller->startupProcess()
#7 C:\wamp\www\cdx\lib\Cake\Routing\Dispatcher.php(161): Dispatcher->_invoke(Object(UsersController), Object(CakeRequest), Object(CakeResponse))
#8 C:\wamp\www\cdx\app\webroot\index.php(92): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#9 {main}
我怎样才能找到使我的请求进入黑洞的原因?
当我尝试使用自定义黑洞处理程序时,错误的类型是auth
. 但这就是我能得到的所有信息
我的 CakePHP 版本是 2.3.1
编辑:登录在没有Security
组件的情况下运行良好。将其添加到 后AppController
,登录停止工作。
EDIT2:我在表格中没有任何data[_Token][key]
字段
EDIT3 解决方案:我团队中的某个人已经覆盖了 HTMLHelper 类,并且它错过了 _tags 数组中的“hiddenblock”,导致缺少 _Token 字段。有关详细信息,请参阅我和 thaJeztah 的答案以及下面的评论