captcha.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. def read_config(self, config):
  17. self.recaptcha_private_key = config["recaptcha_private_key"]
  18. self.recaptcha_public_key = config["recaptcha_public_key"]
  19. self.enable_registration_captcha = config["enable_registration_captcha"]
  20. self.captcha_bypass_secret = config.get("captcha_bypass_secret")
  21. self.recaptcha_siteverify_api = config["recaptcha_siteverify_api"]
  22. def default_config(self, **kwargs):
  23. return """\
  24. ## Captcha ##
  25. # This Home Server's ReCAPTCHA public key.
  26. recaptcha_public_key: "YOUR_PUBLIC_KEY"
  27. # This Home Server's ReCAPTCHA private key.
  28. recaptcha_private_key: "YOUR_PRIVATE_KEY"
  29. # Enables ReCaptcha checks when registering, preventing signup
  30. # unless a captcha is answered. Requires a valid ReCaptcha
  31. # public/private key.
  32. enable_registration_captcha: False
  33. # A secret key used to bypass the captcha test entirely.
  34. #captcha_bypass_secret: "YOUR_SECRET_HERE"
  35. # The API endpoint to use for verifying m.login.recaptcha responses.
  36. recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify"
  37. """