Reputation: 168
I has a action to change password. I dont understand why $error is null;
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)
);
}
and my view changepassword
<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>
When user don't fill full of field we have error message if it success redirect to homepage. Thank for advance!
Upvotes: 0
Views: 853
Reputation:
It's initialized to null and, according to your code, will only be initialized to something if
So, if your user inputs the wrong 'oldpassword', then there's no error.
You want an else for this statement.
if ($player->password != EncryptManager::encryptPassword($_REQUEST['oldpassword']))
Upvotes: 1