D61-IA / stellar-gnosis

Gnosis paper management and collaboration tool
Apache License 2.0
0 stars 1 forks source link

Django recaptcha implementation #15

Closed LuXinliang0559 closed 4 years ago

LuXinliang0559 commented 5 years ago

This is a pull request which contains the Django-recaptcah implementation -- Feature additions/deletions --

  1. Add recaptcha v2 checkbox to comment forms.
  2. (commented) Add reCaptcha v2 invisible and reCaptcha v3 to comment forms.
  3. Create recaptcha app, mainly for organising js files used by recaptcha and overriding templates provided by django-recaptcha. -- Files/links added/removed --
  4. Add recaptcha app folder that contains templates used for recaptcha widgets and their js files (written in html files).
  5. Add static folder inside recaptcha app, that contains js functions used for reCaptcha v2 checkbox. -- How to use recaptcha --
  6. Download and install package using pip install django-recaptcha
  7. Add ReCaptchaField to your form class at yourApp/forms.py.
  8. To use checkbox
    • you do not need to supply public_key or private_key in the parameters, by default it will look for those keys inside settings.py.
    • add class 'captcha-submit' to the submit button of your form.
    • add 'disabled' attribute to the button.
    • checkbox would still work without them. Having them would grey out submit button if checkbox is not ticked.
  9. To use other recaptchas
    • remove/comment all things added for checkbox, including class 'captcha-submit' and 'disabled' attribute.
  10. To create recaptcha with minimum required parameters: captcha = ReCaptchaField( public_key=RECAPTCHA_PUBLIC_KEY_INV, private_key=RECAPTCHA_PRIVATE_KEY_INV, widget=ReCaptchaV2Invisible, label='' )
  11. You may replace widget value to either ReCaptchaV2Invisible, ReCaptchaV2Checkbox or ReCaptchaV3.
  12. Caveat
    • You are only allowed to place one recaptcha per page, due to the lib's implementation.
  13. For more details see: http://github.com/praekelt/django-recaptcha