cakephpでログインしているユーザーが、自分のユーザー情報(名前、アイコンなど)を編集したい場合どのようにすればいいのでしょうか? 現在コントローラ側が、
lang
1public function edit($id =null) { 2 $user_data =$this->User->find('first',array( 3 'conditions'=>array( 4 'id'=>$id, 5 ) 6 )); 7 $this->set('user_data',$user_data); 8 9 $this->User->id = $id; 10 11 12 if($this->request->is('get')) { 13 $this->request->data = $this->User->read(); 14 15 16 } else { 17 if($this->User->save($this->request->data)) { 18 $this->Icon->saveAll($this->request->data["Icon"]); 19 $this->Session->setFlash('success!'); 20 $this->redirect(array('action'=>'index')); 21 } else { 22 $this->Session->setFlash('failed!'); 23 } 24 }
ビュー側が
lang
1<?php 2 3debug($user_data); 4echo $this->form->create('User',array('type'=>'post','type' => 'file')); 5echo $this->form->input('userId',array('label'=>'名前')); 6echo $this->form->hidden('password',array('value'=>$user_data['User']['password'])); 7 8if(isset($user_data['Icon']['0']['id'])){ 9 echo $this->Form->hidden('Icon.id',array('value'=>$user_data['Icon']['0']['id'])); 10} 11echo $this->Form->hidden('Icon.user_id',array('value'=>$user_data['User']['id'])); 12echo $this->Form->file('Icon.icon'); 13echo $this->Form->error('Icon.icon'); 14 15 16echo $this->form->end('編集する');
でやってみました。
しかしこれだと、現在のハッシュ化されたパスワードを更に書き込んでいるため、二重にハッシュ化されたものが新たに登録されてしまうことになります。なので、最初に入力したパスワードでログインすることができなくなってしまいます。ちなみに、ハッシュ化するのは、beforeSaveで行っています。コードは、
lang
1 public function beforeSave($options = array()) { 2 3 $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); 4 return true; 5 6 }
です。
パスワードなどの知識が色々曖昧です。
ユーザーがパスワードを入力して、自分の情報を変えるにはどのようにすればいいのか。また、自分のパスワードを変えるにはどのようにすればいいのか、教えていただけると嬉しいです。
よろしくお願いします!!!
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。