CakePHP auth / acl无效

时间:2013-12-02 07:38:56

标签: php mysql apache cakephp

DAYS一直困扰着我。

我按照本教程进行身份验证:http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html

我通过运行Security:hash命令测试散列是否正常工作,并将值与数据库中的值进行比较(它是相同的)。

$ this-> Auth-> login()总是会返回false,无论我做什么......请详细说明这种情况......

这在我的localhost wamp服务器上工作正常但在实时服务器上没有(我知道没有php错误)...如果需要,我可以使用ssh进入。

我正在使用CakePHP 2.4.2

我的用户登录方式:

public function login() {
    if ($this->request->is('post')) {
    //echo "<div style=\"padding:10px; border:black 1px solid; margin: 5px;\">" . Security::hash($_POST['data']['User']['password'], 'sha1', true) ."</div>";
    if ($this->Auth->login()) { //if ($this->Auth->login($this->request->data)) {
            return $this->redirect($this->Auth->redirect());
            echo "logged in";
        }
        else {
            echo "login failed";
        }
        if ($this->Session->read('Auth.User')) {
            $this->Session->setFlash('You are logged in!');
            return $this->redirect('/pages/home');
        }
        else {
            //echo "not logged in";
        }
        $this->Session->setFlash(__('Your username or password was incorrect.'));
    }

}

app控制器:

class AppController extends Controller {
    public $components = array(
            'Acl',
            'Auth' => array(
                'authorize' => array(
                    'Actions' => array('actionPath' => 'controllers')
                )
            ),
            'Session'
        );
        public $helpers = array('Html', 'Form', 'Session');
        public function beforeFilter() {
            parent::beforeFilter();
            //Configure AuthComponent
            $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
            $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
            $this->Auth->loginRedirect = array('controller' => 'applications', 'action' => 'index');
            //$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'login');
            $this->Auth->allow('display');
            $this->set('Auth', $this->Auth->user());
        }

}

登录视图:

<?php
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'login')));
echo $this->Form->input('User.username');
echo $this->Form->input('User.password');
echo $this->Form->end('Login');
?>

用户模型:

<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
    // other code.

    public function beforeSave($options = array()) {
        $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
        return true;
    }
    public $belongsTo = array('Group');
    public $actsAs = array('Acl' => array('type' => 'requester'));

    public function parentNode() {
        if (!$this->id && empty($this->data)) {
            return null;
        }
        if (isset($this->data['User']['group_id'])) {
            $groupId = $this->data['User']['group_id'];
        } else {
            $groupId = $this->field('group_id');
        }
        if (!$groupId) {
            return null;
        } else {
            return array('Group' => array('id' => $groupId));
        }
    }

    public function bindNode($user) {
    return array('model' => 'Group', 'foreign_key' => $user['User']['group_id']);
}

}
?>

0 个答案:

没有答案