Auth caching

master
q3k 2014-03-02 23:06:46 +01:00
parent 9353681248
commit 9254dbe535
1 changed files with 7 additions and 1 deletions

View File

@ -48,6 +48,8 @@ class UserManager(object):
def hasBeenCustomized(self):
return False
USER_CACHE = {}
class HackerspaceUserManager(UserManager):
"""A user manager for the Warsaw Hackerspace, uses interal apis."""
def __init__(self):
@ -58,11 +60,15 @@ class HackerspaceUserManager(UserManager):
return password
def findUser(self, username=None):
if username in USER_CACHE:
return USER_CACHE[username]
if username == "dummy":
return DummyUser()
print "finduser: {}".format(username)
if requests.get("https://capacifier.hackerspace.pl/{}/{}".format(self.group, username)).status_code == 200:
return HackerspaceUser(username)
u = HackerspaceUser(username)
USER_CACHE[username] = u
return u
else:
return None