コード例 #1
0
 def get_profile_by_id(self, profileid):
     try:
         return Profile.select().join(
             User).where((Profile.id == profileid) & (User.deleted == 0)
                         & (Profile.deleted == 0)).get()
     except Profile.DoesNotExist:
         return None
コード例 #2
0
 def get_profile_by_uniquenick(self, uniquenick, namespaceid, partnercode):
     try:
         if namespaceid == 0:
             the_uniquenick = Profile.select().join(User).where(
                 (Profile.uniquenick == uniquenick)
                 & (User.partnercode == partnercode) & (User.deleted == 0)
                 & (Profile.deleted == 0)).get()
         else:
             the_uniquenick = Profile.select().join(User).where(
                 (Profile.uniquenick == uniquenick)
                 & (Profile.namespaceid == namespaceid)
                 & (User.partnercode == partnercode) & (User.deleted == 0)
                 & (Profile.deleted == 0)).get()
         return the_uniquenick
     except Profile.DoesNotExist:
         return None
コード例 #3
0
    def get_keyed_data(self, persist_data, key):
        ret = {}
        profile = None
        game = None
        try:
            profile = Profile.select().where(
                (Profile.id == persist_data["profileid"])).get()
            game = Game.select().where(
                (Game.id == persist_data["game_id"])).get()
        except (PersistKeyedData.DoesNotExist, Profile.DoesNotExist) as e:
            pass
        try:
            where = (PersistKeyedData.key_name == key) & (
                PersistKeyedData.data_index == persist_data["data_index"]) & (
                    PersistKeyedData.persist_type == persist_data["data_type"]
                ) & (PersistKeyedData.profileid
                     == profile.id) & (PersistKeyedData.gameid == game.id)
            if "modified_since" in persist_data:
                where = (where) & (PersistKeyedData.modified >
                                   persist_data["modified_since"])
            data_entry = PersistKeyedData.select().where(where).get()
            ret = model_to_dict(data_entry)
            ret["modified"] = calendar.timegm(ret["modified"].utctimetuple())
            del ret["profile"]
        except (PersistKeyedData.DoesNotExist) as e:
            pass

        return ret
コード例 #4
0
    def set_persist_raw_data(self, persist_data):
        profile = None
        game = None
        try:
            profile = Profile.select().where(
                (Profile.id == persist_data["profileid"])).get()
            game = Game.select().where(
                (Game.id == persist_data["game_id"])).get()
        except (PersistKeyedData.DoesNotExist, Profile.DoesNotExist) as e:
            pass
        try:

            data_entry = PersistData.select().where(
                (PersistData.data_index == persist_data["data_index"])
                & (PersistData.persist_type == persist_data["data_type"])
                & (PersistData.profileid == profile.id)
                & (PersistData.gameid == game.id)).get()
            data_entry.base64Data = persist_data["data"]
            data_entry.modified = datetime.utcnow()

            data_entry.save()
        except (PersistData.DoesNotExist) as e:
            data_entry = PersistData.create(
                base64Data=persist_data["data"],
                data_index=persist_data["data_index"],
                persist_type=persist_data["data_type"],
                modified=datetime.utcnow(),
                profileid=persist_data["profileid"],
                gameid=persist_data["game_id"])

        ret = model_to_dict(data_entry)
        del ret["profile"]

        ret["modified"] = calendar.timegm(ret["modified"].utctimetuple())
        return ret
コード例 #5
0
 def get_profile_by_nick_email(self, nick, namespaceid, email, partnercode):
     try:
         return Profile.select().join(User).where(
             (Profile.nick == nick) & (Profile.namespaceid == namespaceid)
             & (User.email == email) & (User.deleted == 0)
             & (Profile.deleted == 0)).get()
     except Profile.DoesNotExist:
         return None
コード例 #6
0
    def handle_get_profiles(self, data):
        response = {"success": False}
        profiles = []
        try:
            for profile in Profile.select().where(
                (Profile.userid == data["userid"])
                    & (Profile.deleted == False)):
                profile_dict = model_to_dict(profile)
                profiles.append(profile_dict)
            response["success"] = True
        except Profile.DoesNotExist:
            raise OS_Auth_NoSuchUser()

        response["profiles"] = profiles
        return response
コード例 #7
0
    def validate_request(self, xml_tree):
        request_info = {"success": False}
        game_id = xml_tree.find("{http://gamespy.net/sake}gameid").text
        secretkey = xml_tree.find("{http://gamespy.net/sake}secretKey").text
        loginTicket = xml_tree.find(
            "{http://gamespy.net/sake}loginTicket").text
        #gameid = xml_tree.find()
        #print("GameID: {}\n".format(game_id))
        game = Game.select().where(Game.id == game_id).get()
        profile = Profile.select().where(Profile.id == 10000).get()
        #print("Profile: {}\nGame: {}\n{} - {}\n".format(profile,game, game.secretkey, secretkey))
        if game.secretkey != secretkey:
            return request_info

        request_info["success"] = True
        request_info["game"] = game
        request_info["profile"] = profile
        return request_info
コード例 #8
0
    def update_or_create_keyed_data(self, persist_data, key, value):
        profile = None
        game = None
        try:
            profile = Profile.select().where(
                (Profile.id == persist_data["profileid"])).get()
            game = Game.select().where(
                (Game.id == persist_data["game_id"])).get()
        except (Profile.DoesNotExist, Game.DoesNotExist) as e:
            pass
        try:

            data_entry = PersistKeyedData.select().where(
                (PersistKeyedData.key_name == key)
                & (PersistKeyedData.data_index == persist_data["data_index"])
                & (PersistKeyedData.persist_type == persist_data["data_type"])
                & (PersistKeyedData.profileid == profile.id)
                & (PersistKeyedData.gameid == game.id)).get()
            data_entry.key_value = value
            data_entry.modified = datetime.utcnow()

            data_entry.save()
        except (PersistKeyedData.DoesNotExist) as e:
            data_entry = PersistKeyedData.create(
                key_name=key,
                key_value=value,
                data_index=persist_data["data_index"],
                persist_type=persist_data["data_type"],
                modified=datetime.utcnow(),
                profileid=persist_data["profileid"],
                gameid=persist_data["game_id"])

        ret = model_to_dict(data_entry)
        del ret["profile"]

        ret["modified"] = calendar.timegm(ret["modified"].utctimetuple())
        return ret
コード例 #9
0
    def handle_profile_search(self, search_data):

        #{u'chc': 0, u'ooc': 0, u'i1': 0, u'pic': 0, u'lon': 0.0, u'mar': 0, u'namespaceids': [1], u'lat': 0.0,
        #u'birthday': 0, u'mode': u'profile_search', u'partnercode': 0, u'ind': 0, u'sex': 0, u'email': u'*****@*****.**'}

        profile_search_data = search_data["profile"]
        user_seach_data = search_data["user"]

        where_expression = ((Profile.deleted == False) &
                            (User.deleted == False))

        #user search
        if "userid" in profile_search_data:
            where_expression = ((where_expression) &
                                (User.id == profile_search_data["userid"]))
        elif "id" in user_seach_data:
            where_expression = ((where_expression) &
                                (User.id == user_seach_data["id"]))

        if "email" in user_seach_data:
            where_expression = ((where_expression) &
                                (User.email == user_seach_data["email"]))

        if "partnercode" in profile_search_data:
            where_expression = (
                (where_expression) &
                (User.partnercode == profile_search_data["partnercode"]))

        #profile search
        if "id" in profile_search_data:
            where_expression = ((where_expression) &
                                (Profile.id == profile_search_data["id"]))

        if "nick" in profile_search_data:
            where_expression = ((where_expression) &
                                (Profile.nick == profile_search_data["nick"]))

        if "uniquenick" in profile_search_data:
            where_expression = (
                (where_expression) &
                (Profile.uniquenick == profile_search_data["uniquenick"]))

        if "firstname" in profile_search_data:
            where_expression = (
                (where_expression) &
                (Profile.firstname == profile_search_data["firstname"]))

        if "lastname" in profile_search_data:
            where_expression = (
                (where_expression) &
                (Profile.firstname == profile_search_data["lastname"]))

        if "icquin" in profile_search_data:
            where_expression = (
                (where_expression) &
                (Profile.icquin == profile_search_data["icquin"]))

        if "namespaceids" in profile_search_data:
            namespace_expression = None
            for namespaceid in profile_search_data["namespaceids"]:
                if namespace_expression == None:
                    namespace_expression = (Profile.namespaceid == namespaceid)
                else:
                    namespace_expression = ((Profile.namespaceid
                                             == namespaceid) |
                                            (namespace_expression))
            if namespace_expression != None:
                where_expression = (where_expression) & (namespace_expression)

        profiles = Profile.select().join(User).where(where_expression)
        ret_profiles = []
        for profile in profiles:
            append_profile = model_to_dict(profile)
            append_profile['userid'] = append_profile['user']['id']
            del append_profile['user']['password']

            ret_profiles.append(append_profile)

        return {"profiles": ret_profiles, "success": True}