Hi,
I am very new to Yii and I am trying to implement Password Change option to
the users in my project.
I have created a separate view and controller for this.
This is my view (_form)
<div class="row">
<?php echo CHtml::label("Current Password",'old_pwd');?>
<?php echo CHtml::passwordField("old_pwd");?>
</div>
<div class="row">
<?php echo CHtml::label("New Password",'new_pwd');?>
<?php echo CHtml::passwordField("new_pwd");?>
</div>
<div class="row">
<?php echo CHtml::label("Confirm New Password",'new_pwd_rept');?>
<?php echo CHtml::passwordField("new_pwd_rept");?>
</div>
From this _form I need to call a function(changePassword) in the controller to update the user password
This is my function in the controller
public function changePassword()
{
echo "<br>Inside Action<br>";
$this->_old_pwd = SHA1($_POST['old_pwd']);
$this->_new_pwd = SHA1($_POST['new_pwd']);
$this->_new_pwd_repeat = SHA1($_POST['new_pwd_rept']);
if((Yii::app()->user->password) === _old_pwd)
{
if(_new_pwd === _new_pwd_repeat)
{
echo "<br>Inside Update<br>";
User::model()->updateByPk($user->id,array('password'=> _new_pwd));
}
else
{
//echo array('confirm'=>'New Passwords Entered is not Matched...!?');
echo "New Passwords Entered is not Matched...";
}
}
else
{
//echo array('confirm'=>'Current Password Typed is Incorrect...!?');
echo "Current Password Typed is Incorrect....";
}
}
Whether my approach is correct? If not pls help me to implement it in the right way.
Thanking you
Sumesh