CakePHP登录始终返回false

时间:2014-02-19 08:01:08

标签: php cakephp authentication authorization

我的项目中需要一个登录/注销系统我已经完成了一个授权类但它对我不起作用,因为登录函数总是返回false 这是我的UserController.php

if ($this->request->is('post')) {
                $this->Auth->fields = array("username"=>"username","password"=>"password");
                debug($this->Auth->login(),false,true);
                if ($this->Auth->login()) {
                    $this->Session->setFlash(__('You are now logged in.'));
                }else{
                    $this->Session->setFlash(__('Invalid username or password, try again'));
                }
                Configure::write('debug', 2); 
                $log = $this->User->getDataSource()->getLog(false, false);       
                debug($log);
            }

另外,我的AppController.php有:

public $components = array(
        'Session',
        'Auth' => array(
            'loginAction' => array(
                'controller' => 'User',
                'action'    => 'login'
            ),
            'loginRedirect' => array('controller' => 'User', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'User', 'action' => 'login'),
            'authError' => "You can't acces that page",
            'authorize' => array('Controller'),
        ));
        public function isAuthorized(){
            return TRUE;
        }
        public function beforeFilter() {
            $this->Auth->authenticate = array('Form');
            $this->Auth->allow('index', 'view');
        }

最后我的模型文件是:

public $validate = array(
            'email' => array(
                'required' => array(
                    'rule' => array("notEmpty"),
                    'message' => 'A E-mail field is required'
                )
            ),'password' => array(
                'required' => array(
                    'rule' => array("notEmpty"),
                    'message' => "A Password field is required"
                )
            )
        );

0 个答案:

没有答案