From 030d556b9c8322da802f29ba736745caa1ee580f Mon Sep 17 00:00:00 2001 From: Nyo Date: Thu, 17 Nov 2016 15:27:27 +0100 Subject: [PATCH] .BANCHO. /api/v1/isOnline now supports both safe and unsafe usernames --- common | 2 +- handlers/apiIsOnlineHandler.py | 4 ++-- objects/osuToken.py | 1 + objects/tokenList.py | 16 +++++++++------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/common b/common index 43a872d..cd9f453 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 43a872d8049c9625bfd5232ec4e3ebd2b51bb15f +Subproject commit cd9f453e2199c112bb3b8fb2e34d3019b1dae3b1 diff --git a/handlers/apiIsOnlineHandler.py b/handlers/apiIsOnlineHandler.py index 2db7295..d14403a 100644 --- a/handlers/apiIsOnlineHandler.py +++ b/handlers/apiIsOnlineHandler.py @@ -18,7 +18,7 @@ class handler(requestsManager.asyncRequestHandler): username = None userID = None if "u" in self.request.arguments: - username = self.get_argument("u") + username = self.get_argument("u").lower().replace(" ", "_") else: try: userID = int(self.get_argument("id")) @@ -29,7 +29,7 @@ class handler(requestsManager.asyncRequestHandler): data["result"] = False else: if username is not None: - data["result"] = True if glob.tokens.getTokenFromUsername(username) is not None else False + data["result"] = True if glob.tokens.getTokenFromUsername(username, safe=True) is not None else False else: data["result"] = True if glob.tokens.getTokenFromUserID(userID) is not None else False diff --git a/objects/osuToken.py b/objects/osuToken.py index 87efa35..965453f 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -27,6 +27,7 @@ class token: # Set stuff self.userID = userID self.username = userUtils.getUsername(self.userID) + self.safeUsername = userUtils.getSafeUsername(self.userID) self.privileges = userUtils.getPrivileges(self.userID) self.admin = userUtils.isInPrivilegeGroup(self.userID, "developer") or userUtils.isInPrivilegeGroup(self.userID, "community manager") self.irc = irc diff --git a/objects/tokenList.py b/objects/tokenList.py index dd681ad..8b9569d 100644 --- a/objects/tokenList.py +++ b/objects/tokenList.py @@ -79,19 +79,22 @@ class tokenList: # Return none if not found return None - def getTokenFromUsername(self, username, ignoreIRC=False): + def getTokenFromUsername(self, username, ignoreIRC=False, safe=False): """ - Get token from a username + Get an osuToken object from an username - username -- username to find - return -- False if not found, token object if found + :param username: normal username or safe username + :param ignoreIRC: if True, consider bancho clients only and skip IRC clients + :param safe: if True, username is a safe username, + compare it with token's safe username rather than normal username + :return: osuToken object or None """ # lowercase - who = username.lower() + who = username.lower() if not safe else username # Make sure the token exists for _, value in self.tokens.items(): - if value.username.lower() == who: + if (not safe and value.username.lower() == who) or (safe and value.safeUsername == who): if ignoreIRC and value.irc: continue return value @@ -105,7 +108,6 @@ class tokenList: userID -- tokens associated to this user will be deleted """ - # Delete older tokens for key, value in list(self.tokens.items()): if value.userID == userID: