captcha.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright 2014-2016 OpenMarket Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from ._base import Config
  15. class CaptchaConfig(Config):
  16. section = "captcha"
  17. def read_config(self, config, **kwargs):
  18. self.recaptcha_private_key = config.get("recaptcha_private_key")
  19. self.recaptcha_public_key = config.get("recaptcha_public_key")
  20. self.enable_registration_captcha = config.get(
  21. "enable_registration_captcha", False
  22. )
  23. self.recaptcha_siteverify_api = config.get(
  24. "recaptcha_siteverify_api",
  25. "https://www.recaptcha.net/recaptcha/api/siteverify",
  26. )
  27. self.recaptcha_template = self.read_template("recaptcha.html")
  28. def generate_config_section(self, **kwargs):
  29. return """\
  30. ## Captcha ##
  31. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  32. # This homeserver's ReCAPTCHA public key. Must be specified if
  33. # enable_registration_captcha is enabled.
  34. #
  35. #recaptcha_public_key: "YOUR_PUBLIC_KEY"
  36. # This homeserver's ReCAPTCHA private key. Must be specified if
  37. # enable_registration_captcha is enabled.
  38. #
  39. #recaptcha_private_key: "YOUR_PRIVATE_KEY"
  40. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  41. # unless a captcha is answered. Requires a valid ReCaptcha
  42. # public/private key. Defaults to 'false'.
  43. #
  44. #enable_registration_captcha: true
  45. # The API endpoint to use for verifying m.login.recaptcha responses.
  46. # Defaults to "https://www.recaptcha.net/recaptcha/api/siteverify".
  47. #
  48. #recaptcha_siteverify_api: "https://my.recaptcha.site"
  49. """