.BANCHO. /api/v1/isOnline now supports both safe and unsafe usernames
This commit is contained in:
parent
d51b304fbe
commit
030d556b9c
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit 43a872d8049c9625bfd5232ec4e3ebd2b51bb15f
|
||||
Subproject commit cd9f453e2199c112bb3b8fb2e34d3019b1dae3b1
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user