我在尝试使用cakephp auth组件时遇到问题

时间:2014-11-21 16:04:52

标签: cakephp authentication

当我尝试使用auth componente登录时,我没有收到任何错误,但它没有登录,也没有将我重定向到任何其他页面。请帮我。这是UtilizadoresController代码:

    <?php
App::uses('AppController', 'Controller');
/**
 * Utilizadores Controller
 *
 * @property Utilizadore $Utilizadore
 * @property PaginatorComponent $Paginator
 * @property SessionComponent $Session
 */
class UtilizadoresController extends AppController {


    public $components = array('Paginator', 'Session');
    public $helpers=array('Session');


    function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('add');


        if($this->action=='add' || $this->action=='edit'){
            $this->Auth->authenticate=$this->utilizadore;
        }



    }
    function login(){

            }


    function logout(){
        $this->redirect($this->Auth->logout());
    }


        }

class AppController扩展Controller {

public $components = array(
'Session',
'Auth' => array(
    'loginAction' => array(
        'controller' => 'utilizadores',
        'action' => 'login'
        )
    )
);

public $helpers=array('Session');


function beforeFilter(){
    $this->Auth->allow('index','view');
    $this->Auth->userModel = 'utilizadore';

    $this->Auth->authError='Por favor, registe-se para vizualizar a pagina.';
    $this->Auth->loginError='Passord ou Username incorrectos.';
    $this->Auth->loginRedirect=array('controller'=>'fichadeobras','action'=>'index');
    $this->Auth->logoutRedirect=array('controller'=>'fichadeobras','action'=>'index');

    $this->set('admin', $this->_isAdmin());
    $this->set('logged_in', $this->_loggedIn());
    $this->set('utilizadores_username',$this->_utilizadoresusername());

}

function _loggedIn(){
    $logged_in = FALSE;
    if($this->Auth->user()){
    $logged_in =TRUE;
    }
    return $logged_in;
}
function _utilizadoresusername(){
    $utilizadores_username=NULL;
    if($this->Auth->user()){
        $utilizadores_username=$this->Auth->utilizadore('username');
    }
    return $utilizadores_username;
}

}

0 个答案:

没有答案