def __init__(self, id): '''Simple User class''' if not Configuration.loginRequired(): # dummy account for when logon is not required. USERS = {"_dummy_": "_dummy_"} else: USERS = {} for user in db.getUsers(): USERS[user['username']] = user['password'] if not id in USERS: raise UserNotFoundError() self.id = id self.password = USERS[id]
class User(UserMixin): '''Simple User class''' if not Configuration.loginRequired(): # dummy account for when logon is not required. USERS = {"_dummy_": "_dummy_"} else: USERS = {} for user in db.getUsers(): USERS[user['username']] = user['password'] def __init__(self, id): if not id in self.USERS: raise UserNotFoundError() self.id = id self.password = self.USERS[id] @classmethod def get(self_class, id): '''Return user instance of id, return None if not exist''' try: return self_class(id) except UserNotFoundError: return None