public function actionFindbymobile() { if (!Yii::$app->request->isPost) { throw new \yii\web\NotFoundHttpException(404); } $code = strtolower(Yii::$app->request->post("code")); $mobile = trim(Yii::$app->request->post("values")); if (!$code || !$mobile) { throw new \yii\web\NotFoundHttpException(404); } // 验证码检查 if ($code != Yii::$app->session['passwordstepcode']) { return json_encode($this->makeRes("fail", "请输入正确的验证码!")); } // 清除验证码 Yii::$app->session['passwordstepcode'] = ""; // 用户检查 if (Rz_user::Usermobile_can_use($mobile)) { return json_encode($this->makeRes("fail", "该手机未注册!")); } // 发送验证码并跳转 $code = Sms::init()->rands(6); $res = Sms::init()->send($mobile, $code); if ($res['statu'] == false) { return json_encode($this->makeRes("fail", "信息发送失败,可能由于该手机过于频繁发送!")); } else { $session = Yii::$app->session; $session->set("passwordstep", ["code" => $code, "type" => "mobile", "values" => $mobile]); return json_encode($this->makeRes("success", \yii\helpers\Url::toRoute('passwordstep/checkuser'))); } }
/** * 注册接收 * * @param data array * @return json; */ public function actionRegist() { $request = Yii::$app->request; if (!$request->isPost || !$request->isAjax) { throw new \yii\web\NotFoundHttpException(404); } // 拿出数据 $data = $request->post("data"); $_Code = trim($data['code']); $_Account = trim($data['account']); $_Passwd = md5($data['passwd']); // 验证验证码 $session = Yii::$app->session; if ($_Code != @$session['send_tmp']['code']) { //返回错误 $res = $this->makeRes('fail', "验证码错误!"); return json_encode($res); } // 清除验证码 $session->set('send_tmp', ''); // 手机号查重 if (!Rz_user::Usermobile_can_use($_Account)) { //返回错误 $res = $this->makeRes('fail', "该号码已经注册!"); return json_encode($res); } // 新建用户 $newUser = new Rz_user(); //$newUser -> account = $_Account; $newUser->password = $_Passwd; $newUser->mobile = $_Account; $newUser->mobile_authentication = 1; $newUser->regist_time = time(); $newUser->regist_ip = $request->userIp; $newUser->save(); $newUser->account = "rz" . substr(strval($newUser->attributes['id'] + 100000000), 1, 8); $newUser->last_login_time_tmp = time(); $newUser->last_login_time = time(); if ($newUser->save()) { $res = $this->makeRes('success', \yii\helpers\Url::toRoute('regist/success')); // 此处应该加上用户登陆成功 $session->set('userid', $newUser->attributes['id']); $session->set('account', $newUser->attributes['account']); $session->set('lgtime', time()); } else { $res = $this->makeRes('fail', "注册用失败!"); } return json_encode($res); }