2013-02-19 81 views
0

我完全迷失在嘗試設置AuthComponent中。 每個登錄失敗。似乎無法讓CakePHP的AuthComponent工作

這裏是我的AppController beforeFilter功能:

public function beforeFilter() { 

    $this->Auth->authenticate = array(
     'all' => array(
      'userModel' => 'ClientUser', 
      'fields' => array(
       'username' => 'login', 
       'password' => 'password' 
      ) 
     ) 
    ); 

    $this->Auth->loginAction = array('controller' => 'client_users', 'action' => 'login'); 
    $this->Auth->loginRedirect = array('controller' => 'static', 'action' => 'clientcenter'); 
    $this->Auth->logoutRedirect = array('controller' => 'static', 'action' => 'home'); 

    // I deny stuff later on 
    $this->Auth->allow(); 
} 

下面是在ClientUsers控制器login功能:

public function login() { 

    // Check login data 
    if ($this->Auth->login()) { 
     return $this->redirect($this->Auth->redirect()); 
    } else { 
     $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth'); 
    } 
} 

,它總是失敗。我不知道爲什麼。

這是我$request->data內容:(我實際使用的「登錄」和「用戶名」作爲字段名,無工作)

ClientUser 
    login: [email protected] 
    password: thepassword 

客戶端密碼散列的模式,使用authcomponent(其。在腳本的頂部是進口我使用的安全哈希函數較早,但也沒有工作):

public function beforeSave($options) { 

    $this->data['ClientUser']['password'] = AuthComponent::password($this->data['ClientUser']['password1']); 

    return true; 
} 
+0

「this-> Auth-> allow();」是一個壞主意。只將某個動作列入白名單,或者至少只將其放在某些控制器中,而不能放在應用控制器中。另外,你的beforeSave看起來很糟糕(儘管它最有可能是不相關的)。你如何包含AuthComponent? – mark 2013-02-19 13:31:43

回答

相關問題