public function actionLogin() { $request = Yii::$app->request; if ($request->isGet) { return $this->renderJSON([], "请使用POST提交", -1); } $mobile = trim($this->post("mobile")); $passwd = trim($this->post("passwd")); if (!preg_match("/^[1-9]\\d{10}\$/", $mobile)) { return $this->renderJSON([], "请输入符合规范的手机号码!", -1); } $user_info = Admin::findOne(['mobile' => $mobile]); $params = ['target_type' => 1, 'target_id' => 0, 'act_type' => 1, 'status' => 0, 'login_name' => $mobile]; if (!$user_info) { AccessLogService::recordAccess_log($params); return $this->renderJSON([], "请输入正确的手机号码和密码!", -1); } if (!$user_info->ckeckPassword($passwd)) { AccessLogService::recordAccess_log($params); return $this->renderJSON([], "请输入正确的手机号码和密码!", -1); } $params['status'] = 1; AccessLogService::recordAccess_log($params); $this->createLoginStatus($user_info); return $this->renderJSON(['url' => "/"]); }
protected function checkLoginStatus() { $request = Yii::$app->request; $cookies = $request->cookies; $auth_cookie = $cookies->get($this->auth_cookie_name); if (!$auth_cookie) { return false; } list($authToken, $uid) = explode("#", $auth_cookie); if (!$authToken || !$uid) { return false; } if ($uid && preg_match("/^\\d+\$/", $uid)) { $userinfo = Admin::findOne(['uid' => $uid]); if (!$userinfo) { $this->removeAuthToken(); return false; } if ($authToken != $this->createAuthToken($userinfo['uid'], $userinfo['mobile'], $userinfo['password'], $_SERVER['HTTP_USER_AGENT'])) { $this->removeAuthToken(); return false; } $this->current_user = $userinfo; $view = Yii::$app->view; $view->params['current_user'] = $userinfo; return true; } return false; }
protected function findUpdateAdminForm($id) { $model = Admin::findOne($id); if ($model == NULL) { throw new NotFoundHttpException('该用户不存在'); } $item = $model->getOldAttributes(); return new UpdateAdminForm([], $item); }