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')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么