2015-01-09 1 views
0

누구도 내게 로그인이 작동하지 않는다는 힌트를 줄 수 있습니까?사용자가 데이터베이스에 추가되었지만 cakePHP2.6.0에 로그인 할 수있는 방법이 없습니다.

사용자를 추가 할 수 있으며 Blowfish 암호가 만들어지고 데이터 집합이 데이터베이스에 저장되지만 로그인 할 수 없습니다.

모델

App::uses('AppModel', 'Model'); 
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth'); 
class Benutzer extends AppModel{ 
public $useTable = 'Benutzer'; 

public $validate = array(
    'username' => array(
     'required' => array(
      'rule' => array('notEmpty'), 
      'message' => 'benötigtes Feld' 
     ) 
    ), 
    'passwort' => array(
     'required' => array(
      'rule' => array('notEmpty'), 
      'message' => 'benötigtes Feld' 
     ) 
    ), 
    'rolle' => array(
     'valid' => array(
      'rule' => array('inList', array('admin', 'author', 'borrow', 'archive')), 
      'message' => 'Please enter a valid role', 
      'allowEmpty' => false) 
    ) 
); 


    public function beforeSave($options = array()) { 
    if (isset($this->data[$this->alias]['passwort'])) { 
     $passwordHasher = new BlowfishPasswordHasher(); 
     $this->data[$this->alias]['passwort'] = $passwordHasher->hash($this->data[$this->alias]['passwort']); 
    } 
    return true; 
} 

AppContorler

public $components = array(
         'DebugKit.Toolbar', 
         'Session', 
         'Paginator' => array(
          'className' => 'Bancha.BanchaPaginator'), 
         'Auth' => array(
          'loginRedirect' => array(
           'controller' => 'posts', 
           'action' => 'index' 
          ), 
          'logoutRedirect' => array(
           'controller' => 'pages', 
           'action' => 'display', 
           'home' 
          ), 
          'authenticate' => array(
           'Form' => array(
            'passwordHasher' => 'Blowfish' 
            ) 
          ), 
         ) 
        ); 

    public function beforeFilter() { 
     $this->Auth->allow('index', 'view'); 
    } 

로그인

public function login() { 

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

     } 

로그인 CTP-파일

<div class="users form"> 
<?php echo $this->Session->flash('auth'); ?> 
<?php echo $this->Form->create('Benutzer'); ?> 
    <fieldset> 
     <legend> 
      <?php echo __('Please enter your username and password'); ?> 
     </legend> 
     <?php echo $this->Form->input('username', array('lable' => 'Username', 'type' => 'text'));?> 
     <?php echo $this->Form->input('passwort', array('lable' => 'Passwort', 'type' => 'password'));?> 
    </fieldset> 
<?php echo $this->Form->end(__('Login')); ?> 
</div> 
+0

데이터베이스의 암호 필드 유형 및 길이 란 무엇입니까? –

답변

0

문제는 '필드'를 정의하지 않았다는 것입니다.

'authenticate' => array(
     'Form' => array(
     'fields' => array(
     'username' => 'username', //Default is 'username' in the userModel 
     'password' => 'passwort' //Default is 'password' in the userModel 
    ) 
관련 문제