public function actionMobile($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(['mobile', 'step' => '2']); } $params['verifyPasswordForm'] = $verifyPasswordForm; } elseif ($step === '2' && Yii::$app->session->has('passwordVerified') && Yii::$app->session['passwordVerified']) { $changeMobileForm = new ChangeMobileForm(); $changeMobileForm->load(Yii::$app->request->post()); if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($changeMobileForm); } if (Yii::$app->request->isPost && $changeMobileForm->change()) { Yii::$app->session->setFlash('success', '手机更换成功!'); return $this->redirect(['mobile']); } $params['changeMobileForm'] = $changeMobileForm; } else { return $this->redirect(['mobile']); } return $this->render('mobile', $params); }
/** * 更换手机号 * * @return array */ public function actionMobile($step = '1') { if ($step === '1') { $model = new ChangeMobileSendRequestForm(); if ($model->load(Yii::$app->request->post(), '') && $model->sendMsg()) { return ['status' => 'success', 'data' => []]; } else { return ['status' => 'fail', 'data' => ['errors' => $model->getErrors('mobile') ?: [Yii::$app->smser->message]]]; } } elseif ($step === '2') { $model = new ChangeMobileForm(); $model->mobile = Yii::$app->session['mobileChange']; // TODO if ($model->load(Yii::$app->request->post(), '') && $model->change()) { return ['status' => 'success', 'data' => ['mobile' => Yii::$app->user->identity->mobile]]; } else { return ['status' => 'fail', 'data' => ['errors' => $model->getErrors()]]; } } else { throw new BadRequestHttpException('参数错误!'); } }