users_app.py 958 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from .user import user
  2. from .user import user_factory
  3. from .user import user_builder
  4. from .users_collection import users_collection
  5. from .app_route import app_route
  6. class users_app(app_route):
  7. def __init__(self, collection: users_collection) -> None:
  8. self.__collection = collection
  9. def login(
  10. self,
  11. nick: str,
  12. password: str
  13. ) -> dict:
  14. target = self.collection.login(nick, password)
  15. if target is None:
  16. return self._fail("Bad nick or password.")
  17. return self._success(apikey = target.apikey)
  18. def get(self, apikey: str) -> dict:
  19. target = self.collection.get(apikey)
  20. if target is None:
  21. return self._fail("User with that ApiKey not exists.")
  22. return self._success(
  23. apikey = target.apikey,
  24. nick = target.nick
  25. )
  26. @property
  27. def collection(self) -> users_collection:
  28. return self.__collection