registration.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. self.auto_join_rooms = config.get("auto_join_rooms", [])
  35. def default_config(self, **kwargs):
  36. registration_shared_secret = random_string_with_symbols(50)
  37. return """\
  38. ## Registration ##
  39. # Enable registration for new users.
  40. enable_registration: False
  41. # If set, allows registration by anyone who also has the shared
  42. # secret, even if registration is otherwise disabled.
  43. registration_shared_secret: "%(registration_shared_secret)s"
  44. # Set the number of bcrypt rounds used to generate password hash.
  45. # Larger numbers increase the work factor needed to generate the hash.
  46. # The default number of rounds is 12.
  47. bcrypt_rounds: 12
  48. # Allows users to register as guests without a password/email/etc, and
  49. # participate in rooms hosted on this server which have been made
  50. # accessible to anonymous users.
  51. allow_guest_access: False
  52. # The list of identity servers trusted to verify third party
  53. # identifiers by this server.
  54. trusted_third_party_id_servers:
  55. - matrix.org
  56. - vector.im
  57. - riot.im
  58. # Users who register on this homeserver will automatically be joined
  59. # to these rooms
  60. #auto_join_rooms:
  61. # - "#example:example.com"
  62. """ % locals()
  63. def add_arguments(self, parser):
  64. reg_group = parser.add_argument_group("registration")
  65. reg_group.add_argument(
  66. "--enable-registration", action="store_true", default=None,
  67. help="Enable registration for new users."
  68. )
  69. def read_arguments(self, args):
  70. if args.enable_registration is not None:
  71. self.enable_registration = bool(
  72. strtobool(str(args.enable_registration))
  73. )