/** * Update password for the current user. */ public function actionUpdatePassword() { $model = new UpdatePasswordForm(); if (isset($_POST['UpdatePasswordForm'])) { $model->attributes = $_POST['UpdatePasswordForm']; if ($model->validate()) { Yii::app()->user->user->password = CPasswordHelper::hashPassword($model->new_password); Yii::app()->user->user->save(); Yii::app()->user->setFlash('success', Yii::t("app", "Le mot de passe de votre compte a été modifié. Veuillez dès maintenant utiliser votre nouveau mot de passe pour vous identifier.")); $this->redirect("index"); } } $this->render('updatePassword', array('model' => $model)); }
public function actionPassword() { $model = new UpdatePasswordForm(); if (isset($_POST['UpdatePasswordForm'])) { $model->attributes = Yii::app()->request->getPost('UpdatePasswordForm'); if ($model->validate()) { Manager::model()->updateByPk(Yii::app()->user->id, array('login_password' => md5($model->new_password))); $this->setFlashMessage('您的密码已更新, 新密码已生效'); $this->redirect($this->getReturnUrl()); } } $this->breadcrumbs = array('修改密码'); $this->render('password', array('model' => $model, 'returnUrl' => $this->getReturnUrl())); }
public function actionChangePassword() { $id = Yii::app()->user->id; $passwordform = new UpdatePasswordForm(); if (isset($_POST['UpdatePasswordForm'])) { $passwordform->attributes = $_POST['UpdatePasswordForm']; if ($passwordform->validate()) { $userlogin = $this->loadModel($id); $userlogin->password = $passwordform->password; if ($userlogin->save()) { $user = Yii::app()->getComponent('user'); $user->setFlash('success', "<strong>Selamat!</strong> Password telah berhasil diubah."); $this->redirect(array('/site/index')); } else { $user = Yii::app()->getComponent('user'); $user->setFlash('error', '<strong>Oh snap!</strong> Change something and try submitting again.'); // what's wrong? get the error message $passwordform->addErrors($userlogin->getErrors()); } } else { $passwordform->addErrors($passwordform->getErrors()); } } $this->render('changePassword', array('model' => $passwordform)); }