验证密码yii框架

时间:2012-08-14 08:17:20

标签: php authentication yii

在模型BaseUser.php中,我定义了$verifyPassword并将其添加到规则

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'),
        );
    }

在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();
            }
        }

我注册了一个新帐户,但是在另一个使用profile'user的函数中...我更改后无法保存。

例如,在功能更改配置文件中按保存按钮...没有任何更改...没有任何警报...没有任何验证通知。

如何解决该问题?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题...

我改变了规则:

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'),
    );
}

我在注册方案中检查'验证密码'

在我的控制器中我定义:

$user = new User('register')