Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在cakephp 2.4中调试AuthComponent_Cakephp - Fatal编程技术网

在cakephp 2.4中调试AuthComponent

在cakephp 2.4中调试AuthComponent,cakephp,Cakephp,我烘焙了一个带有users表的cakephp应用程序,并试图使用Blowfish散列实现身份验证。我的密码字段是一个varchar(255),因此它应该足够长,可以存储散列。应用程序中的所有内容都是默认烘焙输出,以下内容除外 这个问题是我在创建用户后无法登录;我总是被“拒绝访问”。解决这个问题的最佳方法是什么 AppController.php App::uses('Controller', 'Controller'); class AppController extends Controll

我烘焙了一个带有users表的cakephp应用程序,并试图使用Blowfish散列实现身份验证。我的密码字段是一个varchar(255),因此它应该足够长,可以存储散列。应用程序中的所有内容都是默认烘焙输出,以下内容除外

这个问题是我在创建用户后无法登录;我总是被“拒绝访问”。解决这个问题的最佳方法是什么

AppController.php

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

class AppController extends Controller {
    public function beforeFilter(){
        $this->Auth->allow('index', 'view');
    }

    public $components = array(
        'Session',
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email'),
                    'passwordHasher' => 'Blowfish'
                    )
                ),
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'index'),
            'authError' => "Access Denied",
            'authorize' => array('Controller'),
        )
    );

    public function isAuthorized($user){
        return true;
    }
}
public function login(){
    if ($this->request->is('post')) {
        if($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        }
        else {
            $this->Session->setFlash('Access Denied');
        }
    }
}
User.php(模型)

UsersController.php

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

class AppController extends Controller {
    public function beforeFilter(){
        $this->Auth->allow('index', 'view');
    }

    public $components = array(
        'Session',
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email'),
                    'passwordHasher' => 'Blowfish'
                    )
                ),
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'index'),
            'authError' => "Access Denied",
            'authorize' => array('Controller'),
        )
    );

    public function isAuthorized($user){
        return true;
    }
}
public function login(){
    if ($this->request->is('post')) {
        if($this->Auth->login()) {
            $this->redirect($this->Auth->redirect());
        }
        else {
            $this->Session->setFlash('Access Denied');
        }
    }
}
login.ctp

echo $this->Form->create('user');
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->button('Log In', array('type' => 'submit');
echo $this->Form->end();
'调试($this->request);死吧in login函数提供以下输出。密码应该是*还是输入的哈希版本

data => array(
    'user' => array(
        'password' => '*****',
        'email' => 'test@test.com'
    )
)
应该是

echo $this->Form->create('User');
App::uses('AuthComponent', 'Controller/Component');
1) 听@waspinator
echo$this->Form->create('User')

(二)

移除它并将其放入AppController中,它应该

echo $this->Form->create('User');
App::uses('AuthComponent', 'Controller/Component');
3) 评论这句话

//public function beforeFilter(){
//    $this->Auth->allow('index', 'view');
//}

//public function isAuthorized($user){
//        return true;
//}
4) 这是第一次把它放在用户控制器上,这样你就可以保存你的密码了

public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('edit', 'index', 'view);
}