duanlu4371 2012-08-14 08:17
浏览 56
已采纳

验证密码yii框架

In model BaseUser.php, I have define $verifyPassword and add it in rules

public function rules() {
        return array(
            array('name, email, phone_code, phone, country, language, password, role, status', 'required'),
            array('verifyPassword','required', 'on'=>'insert'),
            array('country, role, status, payment', 'numerical', 'integerOnly'=>true),
            array('name, email, active_key', 'length', 'max'=>50),
            array('phone_code', 'length', 'max'=>5),
            array('phone', 'length', 'max'=>30),
            array('language', 'length', 'max'=>10),
            array('password', 'length', 'max'=>32),
            array('verifyPassword', 'length', 'max'=>32),
            array('device_token, token', 'length', 'max'=>100),
            array('created', 'safe'),
            array('country', 'haveToSelect'),
            array('email', 'unique', 'message' => Yii::t('app',"This user's email adress already exists.")),
            array('verifyPassword', 'compare', 'compareAttribute'=>'password'),
            array('device_token, active_key, token, payment, created', 'default', 'setOnEmpty' => true, 'value' => null),
            array('id, name, email, phone_code, phone, country, language, password, role, device_token, active_key, status, token, payment, created', 'safe', 'on'=>'search'),
        );
    }

In ProfileController.php

public function actionIndex()
    {  

        $data = Yii::app()->session['Authentication'];
        $idUserLogin = $data->id;

        $dataUser = Users::model()->findByPk($idUserLogin);

        if (isset($_POST['Users'])) {
            $dataUser->setAttributes($_POST['Users']);

            if($dataUser->save()) {
                Yii::app()->user->setFlash('success',Yii::t('app','Change profile successful!'));
                $this->refresh();
            }
        }

I register a new account successful but in another function which use profile'user... I can't save after change it.

For example, in function change profile when press Save button... nothing change... nothing alert... nothing notification of validate.

How do I resolve that problem?

  • 写回答

1条回答 默认 最新

  • douyan6548 2014-12-14 10:17
    关注

    I sloved that problem...

    I changed rules:

    public function rules() {
        return array(
            array('name, email, phone_code, phone, country, language, password, role, status', 'required'),
            array('verifyPassword','required', 'on'=>'register'),
            array('country, role, status, payment', 'numerical', 'integerOnly'=>true),
            array('name, email, active_key', 'length', 'max'=>50),
            array('phone_code', 'length', 'max'=>5),
            array('checkAgree', 'required', 'requiredValue' => 1, 'message' => 'You must have to agree with...', 'on'=>'register'),
            array('phone', 'length', 'max'=>30),
            array('language', 'length', 'max'=>10),
            array('password', 'length', 'max'=>32),
            array('verifyPassword', 'length', 'max'=>32),
            array('device_token, token', 'length', 'max'=>100),
            array('created', 'safe'),
            array('country', 'haveToSelect'),
            array('email', 'unique', 'message' => Yii::t('app',"This user's email adress already exists.")),
            array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'on'=>'register'),
            array('device_token, active_key, token, payment, created', 'default', 'setOnEmpty' => true, 'value' => null),
            array('id, name, email, phone_code, phone, country, language, password, role, device_token, active_key, status, token, payment, created', 'safe', 'on'=>'search'),
        );
    }
    

    I check 'verifyPassword' on register scenario

    and in my controller i define:

    $user = new User('register')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源