A simple web application that allows invitation based registration to a matrix instance
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

  1. from datetime import datetime
  2. from typing import Tuple
  3. class RegistrationCode:
  4. def __init__(self,
  5. code: str,
  6. creation_time: datetime = datetime.now(),
  7. expiration_time: datetime = None,
  8. usages: int = 0,
  9. max_usages: int = 1):
  10. self.code = code
  11. self.creation_time = creation_time
  12. self.expiration_time = expiration_time
  13. self.usages = usages
  14. self.max_usages = max_usages
  15. @staticmethod
  16. def from_db(db_registration_code: Tuple) -> 'RegistrationCode':
  17. expiration_time = None if db_registration_code[2] is None else datetime.fromisoformat(db_registration_code[2])
  18. return RegistrationCode(
  19. db_registration_code[0],
  20. datetime.fromisoformat(db_registration_code[1]),
  21. expiration_time,
  22. db_registration_code[3],
  23. db_registration_code[4]
  24. )
  25. def is_expired(self):
  26. return self.expiration_time is not None and self.expiration_time < datetime.now()
  27. class RegisteredUser:
  28. def __init__(self, username: str, registered_time: datetime = datetime.now()):
  29. self.username = username
  30. self.registered_time = registered_time
  31. @staticmethod
  32. def from_db(db_registered_user: Tuple) -> 'RegisteredUser':
  33. return RegisteredUser(
  34. db_registered_user[0],
  35. datetime.fromisoformat(db_registered_user[1])
  36. )