registration.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. """
  3. flaskbb.core.auth.services
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. This modules provides services used in authentication and authorization
  6. across FlaskBB.
  7. :copyright: (c) 2014-2018 by the FlaskBB Team.
  8. :license: BSD, see LICENSE for more details.
  9. """
  10. from abc import abstractmethod
  11. import attr
  12. from ..._compat import ABC
  13. @attr.s(hash=True, cmp=False, repr=True, frozen=True)
  14. class UserRegistrationInfo(object):
  15. """
  16. User registration object, contains all relevant information for validating
  17. and creating a new user.
  18. """
  19. username = attr.ib()
  20. password = attr.ib(repr=False)
  21. email = attr.ib()
  22. language = attr.ib()
  23. group = attr.ib()
  24. class UserValidator(ABC):
  25. """
  26. Used to validate user registrations and stop the registration process
  27. by raising a
  28. :class:`ValidationError<flaskbb.core.exceptions.ValidationError>`.
  29. """
  30. @abstractmethod
  31. def validate(self, user_info):
  32. """
  33. This method is abstract.
  34. :param user_info: The provided registration information.
  35. :type user_info: :class:`UserRegistrationInfo<flaskbb.core.auth.registration.UserRegistrationInfo>`
  36. """
  37. def __call__(self, user_info):
  38. return self.validate(user_info)
  39. class UserRegistrationService(ABC):
  40. """
  41. Used to manage the registration process. A default implementation is
  42. provided however, this interface is provided in case alternative
  43. flows are needed.
  44. """
  45. @abstractmethod
  46. def register(self, user_info):
  47. """
  48. This method is abstract.
  49. :param user_info: The provided user registration information.
  50. :type user_info: :class:`UserRegistrationInfo<flaskbb.core.auth.registration.UserRegistrationInfo>`
  51. """
  52. pass