2014-12-19 6 views
0

테이블 이름이 admin_users이고 여기에 인증 구성 요소를 사용하려고합니다. 그래서 내가 해시 암호의 adminusers 컨트롤러CakePHP : 2.4 인증 구성 요소가 작동하지 않습니다.

public function login() { 
    $this->layout = 'login'; 
    if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 
      return $this->redirect($this->Auth->redirect()); 
     } 
     $this->Session->setFlash(__('Invalid username or password, try again')); 
    } 
} 

에서) 메소드 호출 로그인 (만든

public function beforeFilter() { 
    //$this->Auth->allow(); 
    $this->set('logged_in', $this->Auth->loggedIn()); 
    $this->set('current_user',$this->Auth->user()); 
    parent::beforeFilter(); 
     $this->Paginator->settings = array(
      'limit'=>4 
    ); 


} 

를 작성한 설정 사용자에 대해 AppController가 울부 짖는 코드

public $components = array('Session','RequestHandler','Paginator'=>array('limit'=>4),'Auth'=>array(
     'loginAction'=>array(
     'controller'=>'adminusers', 
     'action'=>'login' 
     ), 
     'loginRedirect' => array('controller' => 'adminusers','action' => 'index'), 
     'logoutRedirect' => array('controller' => 'adminusers','action' => 'index'), 
     'authError'=>'You can not access this page!!', 
     )); 

에 쓴 AdminUser 모델로 작성했습니다.

public function beforeSave($options = array()) { 
    if (isset($this->data[$this->alias]['password'])) { 
     $passwordHasher = new SimplePasswordHasher(); 
     $this->data[$this->alias]['password'] = $passwordHasher->hash(
      $this->data[$this->alias]['password'] 
     ); 
    } 
    return true; 
} 
나는, 그것은 "저를주고 로그인하려고 할 때

이 사용 가능() mathod 후, 사용자 및 문제 해결 됐었 작업 여기 해시 암호를 생성 한

   <?php echo $this->Form->create('AdminUser'); ?> 
       <?php 
        echo $this->Form->input('username',array(
         'label' => false, 
         'placeholder'=>'UserName' 
         )); 
        echo $this->Form->input('password',array(
         'label' => false, 
         'placeholder'=>'Password' 
        )); 
       ?> 

login.ctp입니다 잘못된 사용자 이름 또는 암호입니다. 다시 시도하십시오. "

+0

검색어가 생성되었는지 확인 했습니까? 해시 된 암호도 확인하십시오 – Dreamer

+0

컨트롤러 이름이 비범하게 보입니다. adminusers도 admin_users 여야합니다. – mark

답변

1

login.ctp에서 AdminUser를 만듭니다. 인증은 기본적으로 '사용자'모델을 사용합니다. Auth-Component에서 사용자 자신의 모델을 정의해야합니다.

public $components = array('Session','RequestHandler','Paginator'=>array('limit'=>4),'Auth'=>array(
    'loginAction'=>array(
    'controller'=>'adminusers', 
    'action'=>'login' 
    ), 
    'loginRedirect' => array('controller' => 'adminusers','action' => 'index'), 
    'logoutRedirect' => array('controller' => 'adminusers','action' => 'index'), 
    'authError'=>'You can not access this page!!', 
    'authenticate' => array(
     'Form' => array(
      'userModel' => 'AdminUser', 
      'passwordHasher' => 'Blowfish' 
     ) 
    ) 
)); 
관련 문제