2012-07-30 4 views
0

cakephp 2.1을 사용하고 있는데 암호 기억 요청을 잊었을 때 사용자가받을 링크를 통해 사용자의 암호를 변경하려고합니다.Cakephp 암호 변경이 작동하지 않습니다.

링크는이

../myApp/users/change_password/1

내가 링크에 사용자 ID를 전달하는 것 같은 뭔가를 보인다. 즉, 상기와 같이 1이다.

뷰 즉은, change_password.ctp는

<?php echo $this->Form->create('User', array('controller' => 'users', 'action' => 'change_password', 'class' => 'well')); ?> 
<?php echo $this->Form->input('User.id',array('value' => $this->params['pass'][0],'type'=>'hidden')); ?> 
<?php echo $this->Form->label('password', 'Password', array('class' => 'control-label')); ?> 
<?php echo $this->Form->password('password', array('class' => 'span3', 'type' => 'password')); ?> 
<?php echo $this->Form->error('password', null , array('wrap' => 'span', 'class' => 'help-inline')); ?> 
<?php echo $this->Form->submit('Change Password', array('class' => 'btn')); ?> 
<?php echo $this->Form->end(); ?> 

다음과 같습니다 그리고

public function change_password() { 
if($this->request->is('post')) {         
    if ($this->User->save($this->request->data)) { 
     $this->Session->setFlash('Password has been changed.', 'default/flash_success'); 
     $this->redirect(array('controller' => 'movies', 'action' => 'index')); 
     } else { 
    $this->Session->setFlash('Password could not be changed.', 'default/flash_error'); 
    $this->redirect(array('controller' => 'movies', 'action' => 'index')); 
    } 
} 

}

을 다음하지만 암호를 저장할 수 아니에요으로 컨트롤러입니다.

답변

0

그래서 URL의 사용자 ID를 변경하면 다른 사용자의 암호를 변경할 수 있습니까?

/myApp/users/change_password/2 전혀 안전하지 않습니다. 다른 접근법을 재고해야합니다.

그러나 질문에 대한 대답은 다음과 같습니다. 데이터의 유효성이 확인되지 않았으므로 아마 암호를 변경할 수 없습니다. User.php 모델에 설정 유효성 검사 규칙이 있습니까? 그렇다면 사용자를 저장하기 전에 유효성 검사 규칙을 설정 해제해야합니다. 예 : unset($this->User->validate['username']);

모델 검증에 대한 자세한 내용은 documentation

읽기
관련 문제