def _authenticate(self): method = self.request.method token_instance = Token() if method == "POST": the_post = Post() the_header = Headers() user_id = the_post.get_user_id(self) user_id = user_id if user_id else the_header.get_user_id(self) token = the_post.get_token(self) token = token if token else the_header.get_token(self) token_from_db = token_instance.get(user_id) if token_from_db and token_from_db.token == token: result = func(self) else: return self.write( OHHOOperation.dict2json(Result.result_not_login())) elif method == "GET": the_get = Get() the_header = Headers() user_id = the_get.get_user_id(self) user_id = user_id if user_id else the_header.get_user_id(self) token = the_get.get_token(self) token = token if token else the_header.get_token(self) token_from_db = token_instance.get(user_id) if token_from_db and token_from_db.token == token: result = func(self) else: return self.write( OHHOOperation.dict2json(Result.result_not_login())) else: result = func(self) return result
def add_user_accuracy_extension(self, user_id, user_extension_dict): OHHOLog.print_log(user_extension_dict) result = self.user.add_user_extension(user_id, user_extension_dict) nickname = user_extension_dict.get(USER_EXTENSION_NICK_NAME, None) primary_interest = user_extension_dict.get( USER_EXTENSION_PRIMARY_INTEREST, "") primary_interest = OHHOOperation.dict2json(primary_interest) OHHOLog.print_log(user_extension_dict) OHHOLog.print_log(USER_EXTENSION_PRIMARY_INTEREST) OHHOLog.print_log(primary_interest) if nickname is not None: UpdateUserInfo.update_user_info(user_id, name=nickname) # create or update match condition relation = self.user.record_user_and_match_condition.get_nearest_by_user( user_id) if relation and relation.match_condition_id: condition = self.user.match_condition.get_by_id( relation.match_condition_id) else: condition = None condition_id = self.user.add_new_condition(user_id) if condition_id: condition = self.user.match_condition.get_by_id(condition_id) if condition: OHHOLog.print_log(condition.id) self.user.match_condition.update(condition, {"interest": primary_interest}) return result
def send(self, user_id, friend_user_id, content, type): result = Result.result_success() data = dict() data["account_id"] = user_id data["another_account_id"] = friend_user_id data["message"] = content success = self.message.add(data) if success: OHHOLog.print_log("add message to database successfully!") else: OHHOLog.print_log("add message to database failed!") result["add2db"] = success message = dict() msg = dict() msg["content"] = content msg["user_id"] = user_id msg["type"] = type msg["current_timestamp"] = OHHODatetime.get_current_timestamp() message["msg"] = msg success = self.send_message.send_attach_message( user_id, friend_user_id, OHHOOperation.dict2json(message)) OHHOLog.print_log(success) result["send2im"] = success return result
def get(self): print(self.__class__.__name__) self.set_header("Content-Type", "application/json; charset=utf-8") name1 = self.get_argument("name1") name2 = self.get_argument("name2") result = LogicPhoneDistance.add_by_names(name1, name2) OHHOLog.print_log(result) self.write(OHHOOperation.dict2json(result))
def get(self): the_get = Get() user_id = the_get.get_user_id(self) friend_id = the_get.get_friend_id(self) latitude = the_get.get_friend_id(self) longitude = the_get.get_friend_id(self) instance = LogicMapDistance() result = instance.map_distance(user_id, friend_id, latitude, longitude) return self.write(OHHOOperation.dict2json(result))
def get(self): result = dict() base_longitude = float(self.get_argument("base_longitude", 0)) base_latitude = float(self.get_argument("base_latitude", 0)) longitude = float(self.get_argument("longitude", 0)) latitude = float(self.get_argument("latitude", 0)) distance = OHHOOperation.calc_distance(base_latitude, base_longitude, latitude, longitude) result = {"distance": distance} self.write(OHHOOperation.dict2json(result))
def post(self): # name = self.get_body_argument("user_name", None) result = dict() # base_url = the_post.get_base_url(self) user = User() user_id = 4 friend_user_id = 13 log_string = "1234567890" OHHOLog.print_log(log_string) # message = user.get_user_basic_information(user_id, base_url) user.push(log_string, friend_user_id, user_id) # return Result.result_success() self.write(OHHOOperation.dict2json(result))
def post(self): the_post = Post() name = the_post.get_name(self) # timestamp = self.get_body_argument("timestamp", None) data = dict() # if timestamp: # data["timestamp"] = timestamp data["name"] = name print(data) db = DBTestTimestamp() db.add(data) result = {"success": True} return self.write(OHHOOperation.dict2json(result))
def post(self): the_post = Post() name = the_post.get_name(self) user_id = the_post.get_user_id(self) rssi = the_post.get_device_rssi(self) identity_id = the_post.get_device_identity_id(self) data = dict() data["name"] = name data["user_id"] = user_id data["rssi"] = rssi data["identity_id"] = identity_id db = DBTestDevice() if user_id: db.add(data) result = Result.result_success() self.write(OHHOOperation.dict2json(result))
def get(self): the_get = Get() user_id = the_get.get_user_id(self) friend_user_id = the_get.get_friend_id(self) is_delete = the_get.get_delete(self) user = User() meet = Meet() the_user = user.get_by_id(user_id) the_friend = user.get_by_id(friend_user_id) if is_delete: met_instance = meet.get_met_by_users(user_id, friend_user_id) success = meet.met.delete(met_instance) if success: result = Result.result_success("delete successfully!") else: result = Result.result_failed("delete failed!") else: if the_user and the_friend: success = meet.add_apply(user_id, friend_user_id) if success: apply = meet.get_apply_by_user_and_friend( user_id, friend_user_id) if apply: data = dict() data["apply_id"] = apply.id data["user_id"] = user_id data["another_user_id"] = friend_user_id success = meet.add_met(data) if success: result = Result.result_success("add successfully!") else: result = Result.result_failed("add met failed!") else: result = Result.result_failed("get apply failed!") else: result = Result.result_failed("add apply failed!") else: result = Result.result_failed("user does not exist!") self.write(OHHOOperation.dict2json(result))
def get(self): # name = self.get_body_argument("user_name", None) the_get = Get() result = dict() base_url = the_get.get_base_url(self) user_id = the_get.get_user_id(self) friend_user_id = the_get.get_friend_id(self) user = User() friend_user_id2 = user_id if user_id else 4 user_id = 4 friend_user_id = friend_user_id if friend_user_id else 13 log_string = "1234567890" OHHOLog.print_log(log_string) # message = user.get_user_basic_information(user_id, base_url) for i in range(100): OHHOLog.print_log(user.push(str(i), friend_user_id, user_id)) OHHOLog.print_log(user.push(str(i), friend_user_id2, user_id)) # return Result.result_success() self.write(OHHOOperation.dict2json(Result.result_success()))
def post(self): name = self.get_body_argument("name", None) phone_name = self.get_body_argument("phone_name", None) # OHHOLog.print_log(phone_name) # OHHOLog.print_log(type(phone_name)) environment = self.get_body_argument("environment", None) # OHHOLog.print_log(environment) timestamp = self.get_body_argument("timestamp", None) rssi = self.get_body_argument("rssi", None) tx_power = self.get_body_argument("tx_power", None) compute_distance = self.get_body_argument("compute_distance", None) input_distance = self.get_body_argument("input_distance", None) kwargs = dict() if name is not None: kwargs["name"] = name if environment is not None: kwargs["environment"] = environment if timestamp is not None: kwargs["timestamp"] = timestamp if phone_name is not None: kwargs["phone_name"] = phone_name if rssi is not None: kwargs["rssi"] = rssi if tx_power is not None: kwargs["tx_power"] = tx_power if compute_distance is not None: kwargs["compute_distance"] = compute_distance if input_distance is not None: kwargs["input_distance"] = input_distance result = LogicDeviceInformation.add(kwargs) self.set_status(status_code=201) self.write(OHHOOperation.dict2json(result))
def get(self): apply = DBOHHORecordMatchApply() apply.delete_all() agree = DBOHHORecordMatchApply() agree.delete_all() refuse = DBOHHORecordMatchApply() refuse.delete_all() exclude = DBOHHORecordMatchApply() exclude.delete_all() duplex_agree = DBOHHORecordMatchDuplexAgree() duplex_agree.delete_all() meeting = DBOHHORecordMatchMeeting() meet = DBOHHORecordMatchMeet() meet_end = DBOHHORecordMatchMeetEnd() met = DBOHHORecordMatchMet() meeting.delete_all() meet.delete_all() meet_end.delete_all() met.delete_all() friend_apply = DBOHHORecordFriendApply() friend_agree = DBOHHORecordFriendAgree() friend_refuse = DBOHHORecordFriendRefuse() friend_apply.delete_all() friend_agree.delete_all() friend_refuse.delete_all() relation = DBOHHOIMUserRelation() relation.delete_all() # 使上面的语句生效 apply.commit() result = Result.result_success() return self.write(OHHOOperation.dict2json(result))
def _permission(self): username = self.current_user if not username: return self.write( OHHOOperation.dict2json(Result.result_not_login())) else: class_name = self.__class__.__name__ if class_name.endswith("AddHandler"): the_type = "AddHandler" elif class_name.endswith("ListHandler"): the_type = "ListHandler" elif class_name.endswith("DetailHandler"): the_type = "DetailHandler" elif class_name.endswith("DeleteHandler"): the_type = "DeleteHandler" else: the_type = "" if the_type: the_type_length = len(the_type) name = class_name[:-the_type_length] permission_instance = OHHOPermission() page = permission_instance.get_or_create_page_from_permission( name) flag = True permission = permission_instance.get_the_page_permission_from_permission( username, page) OHHOLog.print_log(username) OHHOLog.print_log(page.id) OHHOLog.print_log(permission) print(permission) if the_type == "AddHandler": if permission["insert"]: pass else: flag = False elif the_type == "ListHandler": if permission["select"]: pass else: flag = False elif the_type == "DetailHandler": if permission["update"]: pass else: flag = False elif the_type == "DeleteHandler": if permission["delete"]: pass else: flag = False else: flag = False if not flag: result = Result.result_no_permission() return self.redirect("/backstage/no/permission/?code=" + str(result.get("code", 0)) + "&data=" + str(result.get("detail", ""))) result = func(self) return result
def get(self): result = dict() self.set_status(status_code=200) self.write(OHHOOperation.dict2json(result))
def get(self): apply = DBTestDevice() apply.delete_all() result = Result.result_success() return self.write(OHHOOperation.dict2json(result))
def response(self, result_dict): if self._format == "api": return self.render("api/data.html", dict_data=result_dict) else: return self.write(OHHOOperation.dict2json(result_dict))
def post(self): name1 = self.get_body_argument("name1") name2 = self.get_body_argument("name2") result = LogicPhoneDistance.add_by_names(name1, name2) self.set_status(status_code=201) self.write(OHHOOperation.dict2json(result))
instance = DBOHHOIMUser() response_dict = OHHOOperation.json2dict(response) code = response_dict[RESPONSE_NAME_CODE] if code == RESPONSE_CODE_SUCCESS: info = response_dict[RESPONSE_NAME_INFO] accid = info[RESPONSE_NAME_INFO_ACCID] query = instance.get_query() obj = instance.get_by_account(query, accid) obj = instance.first(obj) if obj: data = dict() data["token"] = info[RESPONSE_NAME_INFO_TOKEN] success = instance.update(obj, data) return success else: data = dict() data["token"] = info[RESPONSE_NAME_INFO_TOKEN] data["account_id"] = info[RESPONSE_NAME_INFO_ACCID] success = instance.add(data) return success return False if __name__ == "__main__": # print("hello, world") from_ = 4 to = 5 body = {"msg": [{"name": 1}]} print(SendMessage.send_message(from_, to, OHHOOperation.dict2json(body)))
def post(self): the_get = Post() device_identities = the_get.get_device_identities(self) identity_list = device_identities.split(",") result = LogicTestGetUserByDevice.get(identity_list) return self.write(OHHOOperation.dict2json(result))