Пример #1
0
    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
Пример #2
0
    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))
Пример #3
0
 def encrypt(self, text):
     cryptor = AES.new(self.key, self.mode, self.key)
     # 加密文本必须是bytes(utf8或ascii),而不能是unicode(str)
     text = OHHOOperation.to_bytes(text)
     # 这里密钥key 长度必须为16(AES-128)、24(AES-192)、或32(AES-256)Bytes 长度.目前AES-128足够用
     length = 16
     count = len(text)
     add = length - (count % length)
     text = text + (b'\0' * add)
     self.ciphertext = cryptor.encrypt(text)
     # 因为AES加密时候得到的字符串不一定是ascii字符集的,输出到终端或者保存时候可能存在问题
     # 所以这里统一把加密后的字符串转化为16进制字符串
     # 以unicode存储文件信息
     return OHHOOperation.to_str(b2a_hex(self.ciphertext))
Пример #4
0
    def max_orientation(self, orientation_list):
        orientation_dict = dict()
        if orientation_list:
            for o in orientation_list:
                if orientation_dict.get(o, None) is None:
                    orientation_dict[o] = 1
                else:
                    orientation_dict[o] += 1

            orientation_dict_list = OHHOOperation.dict_sort_by_value(orientation_dict)
            if orientation_dict_list and len(orientation_dict_list) >= 2:
                if orientation_dict_list[0][1] == orientation_dict_list[1][1]:
                    orientation_dict = dict()
                    for o in orientation_list:
                        if len(o) < 6:
                            if orientation_dict.get(o, None) is None:
                                orientation_dict[o] = 1
                            else:
                                orientation_dict[o] += 1
                        else:
                            first = o[:5]
                            second = o[5:]
                            if orientation_dict.get(first, None) is None:
                                orientation_dict[first] = 1
                            else:
                                orientation_dict[first] += 1
                            if orientation_dict.get(second, None) is None:
                                orientation_dict[second] = 1
                            else:
                                orientation_dict[second] += 1
                    orientation_dict_list = OHHOOperation.dict_sort_by_value(orientation_dict)
                    if orientation_dict_list and len(orientation_dict_list) >= 2:
                        if orientation_dict_list[0][1] == orientation_dict_list[1][1]:
                            orientation_first = orientation_dict_list[0][0]
                            orientation_second = orientation_dict_list[1][0]
                            for o in orientation_list:
                                if orientation_first in o:
                                    return orientation_first
                                elif orientation_second in o:
                                    return orientation_second
                        else:
                            return orientation_dict_list[0][0]
                    else:
                        return None
                else:
                    return orientation_dict_list[0][0]
        else:
            return None
Пример #5
0
    def add_feedback(self, user_id, friend_user_id, apply_id, reason, content,
                     category):
        data = dict()
        data["user_id"] = user_id
        data["another_user_id"] = friend_user_id
        data["apply_id"] = apply_id
        data["reason"] = reason
        data["message"] = content

        if self.apply.get_by_id(apply_id):
            success = self.feedback.add(data)
            category_list = OHHOOperation.json2list(category)
            impression_instance = DBOHHOUserImpression()
            for c in category_list:
                if c:
                    temp = dict()
                    temp["type"] = 1
                    temp["content_id"] = int(c)
                    temp["apply_id"] = apply_id
                    temp["user_id"] = user_id
                    temp["another_user_id"] = friend_user_id
                    impression_instance.add(temp)

            if success:
                result = Result.result_success()
            else:
                result = Result.result_failed()
        else:
            result = Result.result_failed("no valid apply!")
        return result
Пример #6
0
    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
Пример #7
0
    def meet_state(self, user_id, base_url):
        result = Result.result_success()

        result["state"], apply_id = self.meet.get_user_state(user_id)
        result["apply_id"] = apply_id
        if apply_id:
            countdown = self.meet.get_countdown(apply_id)
            # result = OHHOOperation.dict_add_dict(result, temp)
            apply = self.apply.get_by_id(apply_id)
            if apply:
                friend_user_id = apply.another_user_id if apply.one_user_id == int(
                    user_id) else apply.one_user_id
                result["friend_state"], temp = self.meet.get_user_state(
                    friend_user_id, result["apply_id"])
                if result["state"] == PUSH_STATE_TYPE_END_MEET:
                    pass
                else:
                    friend_user_information = self.user.get_basic_user_information(
                        friend_user_id, base_url)
                    friend_user_information["user_id"] = friend_user_id
                    friend_user_information["apply_id"] = apply_id
                    friend_user_information = OHHOOperation.dict_add_dict(
                        friend_user_information, countdown)

                    result["friend_user_information"] = friend_user_information
        OHHOLog.print_log(result)
        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
Пример #9
0
 def get_nearest_poi_name(response):
     pois = AMAP.get_pois(response)
     pois_dict = dict()
     for item in pois:
         pois_dict[item["name"]] = item["distance"]
     pois_dict_list = OHHOOperation.dict_sort_by_value(pois_dict,
                                                       reverse=False)
     return pois_dict_list[0][0] if pois_dict_list else ""
Пример #10
0
 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))
Пример #11
0
 def parse_parameter(data):
     data_dict = OHHOOperation.json2dict(data)
     extension = data_dict.get("extension", dict())
     description_I_am = data_dict.get("I_am", dict())
     description_I_like = data_dict.get("I_like", dict())
     description_I_unlike = data_dict.get("I_unlike", dict())
     description_I_hope = data_dict.get("I_hope", dict())
     return extension, description_I_am, description_I_like, \
            description_I_unlike, description_I_hope
Пример #12
0
    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))
Пример #13
0
    def push_agree(self, to_user_id, user_id, apply_id, base_url, function,
                   type):
        information = self.user.get_basic_user_information(user_id, base_url)
        temp = self.meet.get_countdown(apply_id)
        OHHOLog.print_log(temp)
        information = OHHOOperation.dict_add_dict(information, temp)

        information["apply_id"] = apply_id
        information["function"] = function
        return self.user.push_user_information(to_user_id, type, information)
Пример #14
0
 def add_feedback(self, user_id, feedback_type, content):
     data = dict()
     data["user_id"] = user_id
     data["feedback_type"] = feedback_type
     data["content"] = OHHOOperation.to_bytes(content)
     success = self.feedback.add(data)
     if success:
         result = Result.result_success()
     else:
         result = Result.result_failed()
     return result
Пример #15
0
 def compute_favourite_book(self, user_id, another_user_id):
     query = self.favourite_book.get_query()
     user_query = self.favourite_book.get_by_user(query, user_id)
     another_user_query = self.favourite_book.get_by_user(
         query, another_user_id)
     user_book_isbn = [book.isbn for book in user_query]
     another_user_isbn = [book.isbn for book in another_user_query]
     result = list(
         OHHOOperation.set_intersect_set(set(user_book_isbn),
                                         set(another_user_isbn)))
     return result
Пример #16
0
 def check_code(username, code):
     if TEST:
         return True
     else:
         the_code = Code.get_code(username)
         if the_code:
             the_code_str = OHHOOperation.utf82unicode(the_code)
             if the_code_str == code:
                 Code.delete_code(username)
                 return True
         return False
Пример #17
0
 def add_report(self, user_id, reported_user_id, report_type, content):
     data = dict()
     data["user_id"] = user_id
     data["reported_user_id"] = reported_user_id
     data["report_type"] = report_type
     data["content"] = OHHOOperation.to_bytes(content)
     success = self.report.add(data)
     if success:
         result = Result.result_success()
     else:
         result = Result.result_failed()
     return result
    def get(self):
        the_get = Get()
        instance = OHHOPermission()
        group_id = the_get.get_id(self)
        message = the_get.get_data(self)
        group_name = ""
        if group_id:
            group_id = int(group_id)
            group = instance.group.get_by_id(group_id)
            if group:
                group_name = group.name

        all_page = instance.page.get_query()
        page_ids = [p.id for p in all_page] if all_page else []

        query_group_and_page = instance.group_and_page.get_query()
        query_group_and_page = instance.group_and_page.get_by_group_id(
            query_group_and_page, group_id)
        permission_ids = [p.page_permission_id for p in query_group_and_page
                          ] if query_group_and_page else []

        query_page_permission = instance.page_permission.get_query()
        query_page_permission = instance.page_permission.get_by_page_permission_ids(
            query_page_permission, permission_ids)
        permission_page_ids = [q.page_id for q in query_page_permission
                               ] if query_page_permission else []

        the_page_ids = OHHOOperation.list_minus_list(page_ids,
                                                     permission_page_ids)
        rest_page_list = list()
        for page_id in the_page_ids:
            page = instance.page.get_by_id(page_id)
            temp = dict()
            if page:
                temp["page_id"] = page.id
                temp["page_description"] = page.description
                temp["page_name"] = page.name
            if temp:
                rest_page_list.append(temp)

        return self.render(
            PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_HTML,
            group_id=group_id,
            rest_page_list=rest_page_list,
            group_name=group_name,
            home_list_url=MANAGEMENT_PERMISSION_HOME_URL,
            list_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_LIST_URL +
            "?id=" + str(group_id),
            detail_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DETAIL_URL,
            add_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_ADD_URL + "?id=" +
            str(group_id),
            delete_url=PERMISSION_GROUP_PAGE_RELATION_BACKSTAGE_DELETE_URL,
            message=message)
Пример #19
0
 def compute_favourite_sport(self, user_id, another_user_id):
     query = self.favourite_sport.get_query()
     user_query = self.favourite_sport.get_by_user(query, user_id)
     another_user_query = self.favourite_sport.get_by_user(
         query, another_user_id)
     user_sport_id = [sport.sport_id for sport in user_query]
     another_user_sport_id = [
         sport.sport_id for sport in another_user_query
     ]
     result = list(
         OHHOOperation.set_intersect_set(set(user_sport_id),
                                         set(another_user_sport_id)))
     return result
Пример #20
0
 def update2db(response):
     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]
         obj = DBOHHOIMUser.get_by_account_id(accid)
         if obj:
             data = dict()
             data["token"] = info[RESPONSE_NAME_INFO_TOKEN]
             success = DBOHHOIMUser.update(obj, data)
             return success
     return False
Пример #21
0
 def compute_favourite_music(self, user_id, another_user_id):
     query = self.favourite_music.get_query()
     user_query = self.favourite_music.get_by_user(query, user_id)
     another_user_query = self.favourite_music.get_by_user(
         query, another_user_id)
     user_music_id = [music.music_id for music in user_query]
     another_user_music_id = [
         music.music_id for music in another_user_query
     ]
     result = list(
         OHHOOperation.set_intersect_set(set(user_music_id),
                                         set(another_user_music_id)))
     return result
Пример #22
0
    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))
Пример #23
0
    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))
Пример #24
0
    def push_information(self, map_information, to_user_id, user_id, the_type, apply_id, base_url):
        information = self.user.get_meeting_user_information(user_id, apply_id, base_url)
        information = OHHOOperation.dict_add_dict(information, map_information)
        information["is_blue_tooth"] = 0

        information = self.user.set_map_by_exclude(information, to_user_id, user_id)
        information = self.user.set_map_by_is_online(information, to_user_id, user_id)
        created_at = information.get("created_at", None)
        if created_at:
            del information["created_at"]

        changed_at = information.get("changed_at", None)
        if changed_at:
            del information["changed_at"]
        return self.user.push_user_information(to_user_id, the_type, information)
    def check_verification_code(cellphone_number, code):
        code_in_redis = Code.get_code(cellphone_number)
        if code_in_redis:
            code_in_redis_unicode = OHHOOperation.to_str(code_in_redis)
            OHHOLog.print_log(code_in_redis_unicode)
            OHHOLog.print_log(code)
            if code_in_redis_unicode == code:
                Code.delete_code(cellphone_number)
                result = Result.result_success()
            else:
                result = Result.result_failed()
        else:
            result = Result.result_not_exist()

        return 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))
Пример #27
0
 def add2db(response, properties="", icon=""):
     response_dict = OHHOOperation.json2dict(response)
     if response_dict[RESPONSE_NAME_CODE] == 200:
         info = response_dict[RESPONSE_NAME_INFO]
         token = info[RESPONSE_NAME_INFO_TOKEN]
         account_id = info[RESPONSE_NAME_INFO_ACCID]
         name = info[RESPONSE_NAME_INFO_NAME]
         data_dict = dict()
         data_dict["account_id"] = account_id
         data_dict["token"] = token
         data_dict["name"] = name
         data_dict["properties"] = properties
         data_dict["icon"] = icon
         return DBOHHOIMUser.add(data_dict)
     else:
         return DBOHHOIMUser.get_none()
Пример #28
0
    def post(self):
        the_post = Post()
        self.set_format(the_post.get_format(self))
        device_identities = the_post.get_device_identities(self)
        user_id = the_post.get_user_id(self)
        name = the_post.get_name(self)
        base_url = the_post.get_base_url(self)
        conditions = the_post.get_conditions(self)
        if conditions:
            condition_dict = OHHOOperation.json2dict(conditions)
        else:
            condition_dict = dict()

        instance = LogicMatch()
        result = instance.match(device_identities, user_id, name, condition_dict, base_url)
        return self.response(result)
Пример #29
0
    def get_exclude_user_list_up224hour(self, user_id):
        query = self.exclude.get_query()
        query1 = self.exclude.get_by_user(query, user_id)
        query2 = self.exclude.get_by_exclude_user(query, user_id)
        if self.exclude.is_empty(query1):
            user1_list = list()
        else:
            user1_list = [exclude.exclude_user_id for exclude in query1]

        if self.exclude.is_empty(query1):
            user2_list = list()
        else:
            user2_list = [exclude.user_id for exclude in query2]
        user_id_list = list(set(user1_list + user2_list))
        user_id_list_before24hour = self.get_exclude_user_list(user_id)
        return OHHOOperation.list_minus_list(user_id_list,
                                             user_id_list_before24hour)
Пример #30
0
    def upload_map_position(self, user_id, map_information, apply_id, base_url, timestamp=0):
        # 上传地图坐标,只保存最新的坐标
        information = dict()
        user = self.user.get_by_id(user_id)
        longitude = float(map_information.get("longitude", 0))
        latitude = float(map_information.get("latitude", 0))
        if user:
            if map_information:
                geohash_code = OHHOGeohash.get(latitude, longitude, 6)
                map_information["geohash_code"] = geohash_code
                map_information["timestamp"] = OHHODatetime.get_current_timestamp()
                map_information["user_id"] = user_id
                self.user.set_user_map_information(user.username, map_information)
                self.user.add_user_geo_position(longitude, latitude, user.username)
                self.map.add(map_information)

        self_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, user_id)
        friend_user_id = self.meet.get_another_user_id(apply_id, user_id)
        friend_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, friend_user_id)
        self_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, user_id)

        if friend_state == PUSH_STATE_TYPE_END_MEET or self_state == PUSH_STATE_TYPE_END_MEET:
            information["information"] = {"apply_id": int(apply_id)}
        else:
            information = self.return_map_information(friend_user_id)
            if information.get("information", ""):
                information["information"]["apply_id"] = int(apply_id)
                map_instance = Map()
                information["information"]["orientation"] = map_instance.main(user_id, friend_user_id)
                information["information"]["nearest_poi_name"] = AMAP.get_nearest_poi_name_interface(longitude,
                                                                                                     latitude)
            else:
                information["information"] = {"apply_id": int(apply_id)}

        result = Result.result_success()
        apply_id = int(apply_id)
        temp = self.meet.get_countdown(apply_id)
        result = OHHOOperation.dict_add_dict(result, temp)

        result["data"] = information

        return result