/** * 验证密码 * * @return array */ public function actionVerifyPassword() { $model = new VerifyPasswordForm(); if ($model->load(Yii::$app->request->post(), '') && $model->validate()) { return ['status' => 'success', 'data' => []]; } else { return ['status' => 'fail', 'data' => ['errors' => $model->getErrors('password')]]; } }
public function actionPassword($step = '1') { $params = ['step' => $step]; if ($step === '1') { $verifyPasswordForm = new VerifyPasswordForm(); if ($verifyPasswordForm->load(Yii::$app->request->post()) && $verifyPasswordForm->validate()) { Yii::$app->session['passwordVerified'] = true; return $this->redirect(['password', 'step' => '2']); } $params['verifyPasswordForm'] = $verifyPasswordForm; } elseif ($step === '2' && Yii::$app->session->has('passwordVerified') && Yii::$app->session['passwordVerified']) { $changePasswordForm = new ChangePasswordForm(); $changePasswordForm->load(Yii::$app->request->post()); if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($changePasswordForm); } if (Yii::$app->request->isPost && $changePasswordForm->change()) { Yii::$app->session->setFlash('success', '密码更改成功!'); return $this->redirect(['password']); } $params['changePasswordForm'] = $changePasswordForm; } else { return $this->redirect(['password']); } return $this->render('password', $params); }