public function actionLogin() { $request = Yii::$app->request; if (!$request->isAjax || !$request->isPost) { throw new \yii\web\NotFoundHttpException(404); } $post = $request->post("data"); // 前台提交的数据缺一不可 if (!$post['account'] || !$post['passwd'] || !$post['code']) { throw new \yii\web\NotFoundHttpException(404); } // 检查验证码 $session = Yii::$app->session; if (@$session['login_code'] != strtolower($post['code'])) { return json_encode($this->makeRes('fail', "验证码输入错误!")); } // 用户名密码检查 $account = trim($post['account']); $passwd = md5($post['passwd']); $checkRes = Rz_user::User_login($account, $passwd); if (!$checkRes) { return json_encode($this->makeRes('fail', "用户名或密码错误!")); } // 账户是否被冻结? if ($checkRes['status']) { return json_encode($this->makeRes('fail', "账户被冻结,请联系客服:" . $this->_GOLBELS['cfg_kftel'])); } // 登陆成功 存储信息 删除登陆session 发送跳转请求 $session->remove('login_code'); $session->set('userid', $checkRes['id']); $session->set('account', $checkRes['account']); $session->set('username', $checkRes['nickname']); $session->set('lgtime', time()); return json_encode($this->makeRes('success', "/")); }
public function actionNewpsdset() { $session = Yii::$app->session; if (@$session['passwordstep']['code'] != "checkok") { throw new \yii\web\NotFoundHttpException(404); } $password = trim(Yii::$app->request->post("password")); if (!$password || strlen($password) < 6) { throw new \yii\web\NotFoundHttpException(404); } // 设置密码 // 检测密码设置类型 电话/邮箱 if ($session['passwordstep']['type'] == "email") { $res = Rz_user::find()->where(['email' => $session['passwordstep']['values']])->one(); $res->password = md5($password); $res = $res->save(); } else { if ($session['passwordstep']['type'] == "mobile") { $res = Rz_user::find()->where(['mobile' => $session['passwordstep']['values']])->one(); $res->password = md5($password); $res = $res->save(); } } $session['passwordstep'] = ""; return json_encode($this->makeRes("success", \yii\helpers\Url::toRoute('passwordstep/stepsuccess'))); }
/** * 注册接收 * * @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); }
public function actionModify() { $data = Rz_user::User_info(Yii::$app->session['userid']); return $this->renderPartial('modify', $data); }
public static function User_info($id) { return Rz_user::find()->where(['id' => $id])->asArray()->one(); }