cakePHP预填充密码字段并在更新时中断 [英] cakePHP pre-populates password field and breaks on update

查看:154
本文介绍了cakePHP预填充密码字段并在更新时中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户个人资料更新页面,它预先填充从$ this-> request-> data收集的用户信息的文本字段。一切都很好,除了密码字段预先填充了什么似乎是来自数据库的加密密码,所以保存,它失败验证,因为密码超过允许的字符数,即使它存储,它会

I have a user profile update page, which pre-populates the text fields with the users information gathered from $this->request->data. Everything works fine, except the password field is pre-populated with what appears to be the encrypted password from the database, so on save, it fails the validation as the password exceeds the number of characters allowed, and even if it stores, it will then replace the users actual password with the encrypted same password, if that makes sense.

这是最好的解决方法是什么?

What would be the best work-around for this?

控制器

 public function profile() {
    if($this->request->is('post') || $this->request->is('put')) {
        if($this->Auth->user("id") == $this->request->data['User']['id']) {
            $this->request->data['User']['user_status_id'] = $this->Auth->user("user_status_id");
            $this->request->data['User']['user_type_id'] = $this->Auth->user("user_type_id");
            if($this->User->save($this->request->data)) {
                $this->Session->setFlash('Your profile has been updated','default',array('class'=>'success'));
            } else {
                $this->Session->setFlash("An error has occured updating your profile.");
            }
        } else {
            $this->Session->setFlash("Unable to save this result as there is an ID mismatch.");
        }
    } else {
        $this->request->data = $this->User->read(null,$this->Auth->user("id"));
    }
}

查看: p>

View:

  <h1>Profile</h1>
 <h3>Update your profile</h3>
 <div class="left">
<div class="formContainer">
<?php 
    echo $this->Form->create('User');
        echo $this->Form->input('username',array("id" => "profileUsername"));
        echo $this->Form->input('password',array("id" => "profilePassword"));
        echo $this->Form->input('company');
        echo $this->Form->input('first_name');
        echo $this->Form->input('last_name');
        echo $this->Form->input('telephone');
        echo $this->Form->input('fax');
        echo $this->Form->input('id',array('type' => 'hidden'));
    echo $this->Form->end(__('Update'));
    ?>
 </div>
 </div>


推荐答案

$this->Form->input('password',array('value'=>null));

这篇关于cakePHP预填充密码字段并在更新时中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆