2011-04-26 3 views
0

나는 CakephpTV에 대한 자습서를 따라 AuthComponent에 의한 등록을했다. 어제 모든 것이 좋았지 만 오늘은 그렇지 않습니다.Cakephp 등록 문제

새 계정을 추가하려고하면 암호가 일치하지 않는다고 표시되고 암호 필드에는 해시 된 암호가 있고 암호 확인에는 암호 (일반) (해시가 아닌)가 있습니다.

내 UserController 클래스 :

class UsersController extends AppController 
{ 
    function beforeFilter() { 
     parent::beforeFilter(); 
     $this->Auth->allow('new_user'); 

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

    function new_user() 
    { 
     if (!empty($this->data)) {    
      if ($this->User->save($this->data)) {     
       $this->Session->setFlash('Rejestracja zakończona pomyślnie');     
       $this->redirect(array('action' => 'index'));    
      }   
     } 
    } 

    function login() { 

    } 

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

내 사용자 모델 :

class User extends AppModel { 
    var $name = 'User'; 
    var $validate = array (
     'email' => array(
      'Please supply a valid email address.' => array(
       'rule' => 'email', 
       'message' => 'Please supply a valid email address.' 
      ), 
      'Already exists' => array(
       'rule' => 'isUnique', 
       'message' => 'Must be unique' 
      ) 
     ), 
     'password' => array (
      'aThis field must have between 6 and 40 alphanumeric characters.' => array(
       'rule' => '/^[^\'"]{6,40}$/i', 
       'message' => 'aThis field must have between 6 and 40 alphanumeric characters.' 
      ), 
      'Do not match' => array(
       'rule' => 'matchPasswords', 
       'message' => 'Do not match' 
      ) 
     ) 
); 

    function matchPasswords($data) { 
    if($data['password'] == $this->data['User']['password_confirmation']) { 
     return TRUE; 
    } 
    $this->invalidate('password_confirmation', 'DO not match'); 
    return FALSE; 
    } 

    function hashPasswords($data) { 
    if(isset($this->data['User']['password'])) { 
     $this->data['User']['password'] = Security::hash($this->data['User']['password'], NULL, TRUE); 
     return $data; 
    } 
    return $data; 
    } 

    function beforeSave() { 
    $this->hashPasswords(NULL, TRUE); 
    $this->data['User']['registration_date'] = date("Y-m-d H:i:s"); 
    return TRUE; 
    } 
} 

내 new_user.ctp :

echo $this->Form->create('User', array('action' => 'new_user')); 
    echo $this->Form->input('email'); 
    echo $this->Form->input('password'); 
    echo $this->Form->input('password_confirmation',array('type' => 'password')); 
    echo $this->Form->end('Zarejestruj'); 

내의 AppController 클래스 :

class AppController extends Controller { 
    var $components = array('Auth','Session'); 

    function beforeFilter() { 
     $this->Auth->fields = array('username' => 'email', 'password' => 'password'); 
     $this->Auth->allow('index','view','display','new_user'); 
     $this->Auth->authError = 'Zaloguj się aby zobaczyć tą stronę.'; 
     $this->Auth->loginError = 'Wprowadzono niepoprawne dane.'; 
     $this->Auth->loginRedirect = array('controller'=>'pages','action'=>'home'); 
     $this->Auth->loginRedirect = array('controller'=>'pages','action'=>'home'); 
    } 
} 

답변

3

CakePHP는이라는 필드를 User 모델로 자동 해시합니다. 따라서 양식이 실패 할 때 이미 해시 된 암호를 다시 가져 오는 것입니다. 당신이 돌아올 해시가 돌아올 때와 같은 해시인지 확인하고 싶을 수도 있습니다.

그 외에도 matchPasswords 사용자의 기능에서 $this->data['password']에 대한 점검은 $this->data['User']['password']이어야한다고 생각합니다.

+0

도움이되지 않았습니다. :( – latata