How to change password for Yii?
=====================================================
Create the new action in you controller file :
public function actionChange($id)
{
$model=User::model()->findByPk((int)$id);
$modelForm=new ChangePasswordForm();
if(isset($_POST['ChangePasswordForm']['password']))
{
//print_r($_POST['ChangePasswordForm']['password']);
if((count(CJSON::decode(CActiveForm::validate($modelForm)))>0)) {
$this->render('change',array(
'model'=>$modelForm,
));
Yii::app()->end();
}
$modelForm->password = $_POST['ChangePasswordForm']['password'];
/*
if(!$modelForm->validate()) {
$this->render('change',array('model'=>$modelForm,));
}
*/
//$tmp=array('password'=>Yii::app()->getModule('admin')->encrypting($modelForm->password));
//(($modelForm->password,0);
$model->password=md5($modelForm->password);
$model->save();
if (!$model->hasErrors()) {
echo "Password Change Succesfully";
$this->redirect(array('view','id'=>$id));
}else {
echo "Password change failure!";
$this->redirect(array('view','id'=>$id));
}
//p($model->getErrors());
}
$this->render('change',array(
'model'=>$modelForm,
));
}
=========================================================================================================
=====================================================
Create the new action in you controller file :
public function actionChange($id)
{
$model=User::model()->findByPk((int)$id);
$modelForm=new ChangePasswordForm();
if(isset($_POST['ChangePasswordForm']['password']))
{
//print_r($_POST['ChangePasswordForm']['password']);
if((count(CJSON::decode(CActiveForm::validate($modelForm)))>0)) {
$this->render('change',array(
'model'=>$modelForm,
));
Yii::app()->end();
}
$modelForm->password = $_POST['ChangePasswordForm']['password'];
/*
if(!$modelForm->validate()) {
$this->render('change',array('model'=>$modelForm,));
}
*/
//$tmp=array('password'=>Yii::app()->getModule('admin')->encrypting($modelForm->password));
//(($modelForm->password,0);
$model->password=md5($modelForm->password);
$model->save();
if (!$model->hasErrors()) {
echo "Password Change Succesfully";
$this->redirect(array('view','id'=>$id));
}else {
echo "Password change failure!";
$this->redirect(array('view','id'=>$id));
}
//p($model->getErrors());
}
$this->render('change',array(
'model'=>$modelForm,
));
}
=========================================================================================================
Hahaha, site title must be "Yii Framework"
ReplyDelete
ReplyDeleteWonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!
Hire Remote Yii Developers in India