2016-02-17 22 views
1

大家好我每次嘗試登錄後,我已成功地將用戶數據添加到數據庫,但登錄不工作,我是cakephp.Please新來幫助我。 這裏是代碼

的AppController:

class AppController extends Controller { 
public $components = array(
    'DebugKit.Toolbar' ,'Session', 
    'Auth' => array(
     'loginRedirect' => array('controller' => 'users', 'action' => 'index'), 
     'logoutRedirect' => array('controller' => 'users', 'action' => 'login') 
    ) 
);} 

UsersController:

public function login(){ 
    if ($this->request->is('Post')) { 
     if ($this->Auth->login()) { 
      return $this->redirect($this->Auth->redirectUrl()); 
     }//$this->Flash->error(__('Invalid username or password, try again')); 
    } 
} 

login.ctp:

<?php 
echo $this->Form->create('User'); 
echo $this->Form->input('username'); 
echo $this->Form->input('password'); 
echo $this->Form->end('login'); 

>

+0

你得到了什麼錯誤信息? – JayIsTooCommon

+0

我有dubug $ this-> Auth-> login(),它返回false。 –

+0

我應該改變cakephp版本還是別的?任何幫助請 –

回答

1

添加密碼哈希你的用戶模型

user.php的

App::uses('AppModel', 'Model'); 

class User extends AppModel { 
    public function beforeSave($options = array()) {  
     if(isset($this->data['User']['password'])) { 
      $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); 
     } 

    } 
} 

後截斷用戶表,並保存用戶清新,然後再次檢查登錄。

相關問題