public function login() { header("Content-Type: application/json; charset=utf-8"); if (!CheckReferer($this->agent)) { return; } $this->load->model("Account_model", "AccountModel", true); $post = $this->input->post(); if (!ApiParamValidate($post, ['screen_name', 'password'])) { echo BuildErrorResponse(400, 102, "Some invalid parameters."); return; } $screenName = urldecode($post["screen_name"]); $password = urldecode($post["password"]); $isSuccess = false; if (preg_match("/^[a-z0-9_]+\$/i", $screenName) === 1) { if ($resUser = $this->AccountModel->FindByScreenName($screenName)) { if (password_verify($password, $resUser["password_hash"])) { $isSuccess = true; $res = BuildSuccessResponse("successful."); $data = ["is_login" => true, "me" => $resUser]; $this->session->set_userdata($data); } } } if (!$isSuccess) { $res = BuildErrorResponse(400, 102, "Some invalid parameters."); } echo $res; }
public function friendstatus($meScreenName, $meUserId, $get) { $this->load->model("Account_model", "AccountModel", TRUE); $this->load->model("Friend_model", "FriendModel", TRUE); if (!ApiParamValidate($get, ["screen_name"])) { return; } $screenName = urldecode($get["screen_name"]); if (preg_match("/^[a-z0-9_]+\$/i", $screenName) === 1) { if ($screenName !== $meScreenName) { if ($target = $this->AccountModel->FindByScreenName($screenName)) { $isFollower = $this->FriendModel->IsExist($target["id"], $meUserId); $isFollowing = $this->FriendModel->IsExist($meUserId, $target["id"]); $res = BuildSuccessResponse(["message" => "successful.", "is_follower" => $isFollower, "is_following" => $isFollowing]); } else { $res = BuildErrorResponse(400, 200, "User not found."); } } else { $res = BuildErrorResponse(400, 201, "This user is you."); } } else { $res = BuildErrorResponse(400, 102, "Some invalid parameters."); } return $res; }
public function update($meUserId, $post) { $this->load->model('Status_model', 'StatusModel', TRUE); if (!ApiParamValidate($post, ['text'])) { return; } $text = urldecode($post["text"]); if (strlen($text) <= 400) { if ($status = $this->StatusModel->Create($meUserId, $text, 0)) { $res = BuildSuccessResponse(["message" => "successful.", 'status' => $status]); } else { $res = BuildErrorResponse(500, 105, 'Failed to execute.'); } } else { $res = BuildErrorResponse(400, 100, 'text is too long.'); } return $res; }