.BANCHO. /api/v1/isOnline now supports both safe and unsafe usernames

This commit is contained in:
Nyo 2016-11-17 15:27:27 +01:00
parent d51b304fbe
commit 030d556b9c
4 changed files with 13 additions and 10 deletions

2
common

@ -1 +1 @@
Subproject commit 43a872d8049c9625bfd5232ec4e3ebd2b51bb15f Subproject commit cd9f453e2199c112bb3b8fb2e34d3019b1dae3b1

View File

@ -18,7 +18,7 @@ class handler(requestsManager.asyncRequestHandler):
username = None username = None
userID = None userID = None
if "u" in self.request.arguments: if "u" in self.request.arguments:
username = self.get_argument("u") username = self.get_argument("u").lower().replace(" ", "_")
else: else:
try: try:
userID = int(self.get_argument("id")) userID = int(self.get_argument("id"))
@ -29,7 +29,7 @@ class handler(requestsManager.asyncRequestHandler):
data["result"] = False data["result"] = False
else: else:
if username is not None: 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: else:
data["result"] = True if glob.tokens.getTokenFromUserID(userID) is not None else False data["result"] = True if glob.tokens.getTokenFromUserID(userID) is not None else False

View File

@ -27,6 +27,7 @@ class token:
# Set stuff # Set stuff
self.userID = userID self.userID = userID
self.username = userUtils.getUsername(self.userID) self.username = userUtils.getUsername(self.userID)
self.safeUsername = userUtils.getSafeUsername(self.userID)
self.privileges = userUtils.getPrivileges(self.userID) self.privileges = userUtils.getPrivileges(self.userID)
self.admin = userUtils.isInPrivilegeGroup(self.userID, "developer") or userUtils.isInPrivilegeGroup(self.userID, "community manager") self.admin = userUtils.isInPrivilegeGroup(self.userID, "developer") or userUtils.isInPrivilegeGroup(self.userID, "community manager")
self.irc = irc self.irc = irc

View File

@ -79,19 +79,22 @@ class tokenList:
# Return none if not found # Return none if not found
return None 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 :param username: normal username or safe username
return -- False if not found, token object if found :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 # lowercase
who = username.lower() who = username.lower() if not safe else username
# Make sure the token exists # Make sure the token exists
for _, value in self.tokens.items(): 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: if ignoreIRC and value.irc:
continue continue
return value return value
@ -105,7 +108,6 @@ class tokenList:
userID -- tokens associated to this user will be deleted userID -- tokens associated to this user will be deleted
""" """
# Delete older tokens # Delete older tokens
for key, value in list(self.tokens.items()): for key, value in list(self.tokens.items()):
if value.userID == userID: if value.userID == userID: