registration.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015, 2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from ._base import Config
  16. from synapse.util.stringutils import random_string_with_symbols
  17. from distutils.util import strtobool
  18. class RegistrationConfig(Config):
  19. def read_config(self, config):
  20. self.enable_registration = bool(
  21. strtobool(str(config["enable_registration"]))
  22. )
  23. if "disable_registration" in config:
  24. self.enable_registration = not bool(
  25. strtobool(str(config["disable_registration"]))
  26. )
  27. self.registration_shared_secret = config.get("registration_shared_secret")
  28. self.bcrypt_rounds = config.get("bcrypt_rounds", 12)
  29. self.trusted_third_party_id_servers = config["trusted_third_party_id_servers"]
  30. self.allow_guest_access = config.get("allow_guest_access", False)
  31. self.invite_3pid_guest = (
  32. self.allow_guest_access and config.get("invite_3pid_guest", False)
  33. )
  34. def default_config(self, **kwargs):
  35. registration_shared_secret = random_string_with_symbols(50)
  36. return """\
  37. ## Registration ##
  38. # Enable registration for new users.
  39. enable_registration: False
  40. # If set, allows registration by anyone who also has the shared
  41. # secret, even if registration is otherwise disabled.
  42. registration_shared_secret: "%(registration_shared_secret)s"
  43. # Set the number of bcrypt rounds used to generate password hash.
  44. # Larger numbers increase the work factor needed to generate the hash.
  45. # The default number of rounds is 12.
  46. bcrypt_rounds: 12
  47. # Allows users to register as guests without a password/email/etc, and
  48. # participate in rooms hosted on this server which have been made
  49. # accessible to anonymous users.
  50. allow_guest_access: False
  51. # The list of identity servers trusted to verify third party
  52. # identifiers by this server.
  53. trusted_third_party_id_servers:
  54. - matrix.org
  55. - vector.im
  56. """ % locals()
  57. def add_arguments(self, parser):
  58. reg_group = parser.add_argument_group("registration")
  59. reg_group.add_argument(
  60. "--enable-registration", action="store_true", default=None,
  61. help="Enable registration for new users."
  62. )
  63. def read_arguments(self, args):
  64. if args.enable_registration is not None:
  65. self.enable_registration = bool(
  66. strtobool(str(args.enable_registration))
  67. )