0

我有一个更改密码的操作。我不明白为什么 $error 为空;

public function actionChangePassword() {
    $error;
    $player = $this->loadModel(Yii::app()->user->id);
    $oldpassword = '';
    $newpassword = '';
    $newpasswordrepeat = '';
    if (!isset($_REQUEST['oldpassword']) || !isset($_REQUEST['newpassword']) || !isset($_REQUEST['newpasswordrepeat'])) {
        $error = 'Vui long dien day du';
    }
    if (isset($_REQUEST['newpassword']) && isset($_REQUEST['newpasswordrepeat']) && isset($_REQUEST['oldpassword'])) {
        $oldpassword = $_REQUEST['newpassword'];
        $newpassword = $_REQUEST['newpassword'];
        $newpasswordrepeat = $_REQUEST['newpasswordrepeat'];
        if ($player->password != EncryptManager::encryptPassword($_REQUEST['oldpassword'])) {
            $error = 'Password cu khong dung';
            if ($newpasswordrepeat != $newpassword) {
                $error = 'Lap lai password khong dung';
            }
            if (count($newpassword))
                $error = 'Nhap password phai tren 6 ky tu';
            if (!isset($error)) {
                $player->password = EncryptManager::encryptPassword($_REQUEST['newpassword']);
                echo 'new password';
                if ($player->save()) {
                    $this->redirect(Yii::app()->baseUrl);
                }
            }
        }
    }  
    $this->render('//site/changepassword'
            , array('error' => $error)
    );
}

和我的看法更改密码

<div class="change-password-layout">
    <div class="change-password-content" >
        <?php echo CHtml::beginForm(); ?>
        <div class="change-password-detail-total">
            <div class="change-password-title"><p>Đổi mật khẩu</p></div>
            <div class="change-password-detail">

                <p>Mật khẩu cũ </p>
                <input type="password" name="oldpassword" value="">


            </div>
            <div class="change-password-detail">
                <p>Mật khẩu mới </p>
                <input type="password" name="newpassword" value="">

            </div>


            <div class="change-password-detail">
                <p>Xác nhận lại mật khẩu mới </p>
                <input type="password" name="newpasswordrepeat" value="">

            </div>

            <div class="submit-button">
                <input type="submit" name="" value="Xác nhận">
                <input type="button" name="" value="Hủy bỏ" />
                <div class="clearboth"></div>
            </div>
        </div>
        <?php echo $error; ?>
        <?php echo CHtml::endForm(); ?>
    </div>
    <div class="change-password-bg-total">
        <div class="change-password-bg"></div>
    </div> 



    <?php if ($error != '') { ?>
        <div class="msg-error">
            <div class="signup-line"></div>
            <div class="msg-item">
                <div class="msg-warning-icon"></div>
                <div class="msg-warning-label">
                    <?php echo $error; ?>
                </div>
                <div class="clearboth"></div>
            </div>
            <div style="height:5px"></div>
            <div class="signup-line"></div>
        </div>
    <?php } ?>

</div>


<script>
    $("#set-height").css('height',$(window).height());
</script>

当用户没有填写完整的字段时,如果成功重定向到主页,我们会收到错误消息。感谢提前!

4

1 回答 1

1

它被初始化为 null 并且根据您的代码,只有在以下情况下才会被初始化为

  • 没有任何请求参数被初始化。
  • 初始化所有请求参数,用户存储的密码与旧密码的加密版本相同。(这里有一些嵌套条件会设置它。)

因此,如果您的用户输入了错误的“旧密码”,那么就没有错误。

你想要这个语句的else

if ($player->password != EncryptManager::encryptPassword($_REQUEST['oldpassword']))
于 2012-04-17T19:11:25.670 回答