Skip to content

Commit

Permalink
Allow error to be silenced through django config setting. (#33)
Browse files Browse the repository at this point in the history
* Report error via return value.

* Add note to README.md.
  • Loading branch information
btimby authored May 11, 2024
1 parent 1e74e28 commit 683bdad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ class MobileSerializer(Serializer):
2. the argument `secret_key` of field
3. request.context["recaptcha_secret_key"]

### Silence the check error

If you need to disable the error, you can do so using the django settings.

```python
SILENCED_SYSTEM_CHECKS = ['drf_recaptcha.checks.recaptcha_system_check']
```

## reCAPTCHA v3

Validation is passed if the score value returned by Google is greater than or equal to required score.
Expand Down
8 changes: 5 additions & 3 deletions drf_recaptcha/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.core.checks import Tags, Warning, register
from django.core.checks import Tags, Error, Warning, register
from django.core.exceptions import ImproperlyConfigured

from drf_recaptcha.constants import TEST_V2_SECRET_KEY
Expand All @@ -15,9 +15,11 @@ def recaptcha_system_check(app_configs, **kwargs):

secret_key = getattr(settings, "DRF_RECAPTCHA_SECRET_KEY", None)
if not secret_key:
raise ImproperlyConfigured("settings.DRF_RECAPTCHA_SECRET_KEY must be set.")
errors.append(
Error("settings.DRF_RECAPTCHA_SECRET_KEY must be set."),
)

if secret_key == TEST_V2_SECRET_KEY:
elif secret_key == TEST_V2_SECRET_KEY:
errors.append(
Warning(
"Google test key for reCAPTCHA v2 is used now.\n"
Expand Down

0 comments on commit 683bdad

Please sign in to comment.