/** * 修改面膜 * @return string|\yii\web\Response */ public function actionPassword() { if (Yii::$app->user->isGuest) { return $this->redirect(['/site/login']); } $model = new ResetPasswordForm(Yii::$app->user->identity->password_reset_token); if ($model->load(Yii::$app->request->post()) && $model->resetPassword()) { Yii::$app->user->logout(); return $this->redirect(['/site/login']); } return $this->render('password', ['model' => $model]); }
public function actionResetPassword($token) { try { $model = new ResetPasswordForm($token); } catch (InvalidParamException $e) { throw new BadRequestHttpException($e->getMessage()); } if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { Yii::$app->getSession()->setFlash('success', 'New password was saved.'); return $this->goHome(); } return $this->render('resetPassword', ['model' => $model]); }
public function actionResetPassword() { $this->layout = 'main'; $model = new ResetPasswordForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $user = User::findOne(Yii::$app->user->id); $user->setPassword($model->password); if ($user->save()) { Yii::$app->session->setFlash('success', '修改密码成功'); return $this->goHome(); } } return $this->render('reset-password', ['model' => $model]); }