Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/misl6/py4web-recaptcha
Recaptcha field for py4web
https://github.com/misl6/py4web-recaptcha
Last synced: about 2 months ago
JSON representation
Recaptcha field for py4web
- Host: GitHub
- URL: https://github.com/misl6/py4web-recaptcha
- Owner: misl6
- Created: 2020-05-10T13:34:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-10T13:36:34.000Z (over 4 years ago)
- Last Synced: 2024-10-27T07:23:44.762Z (2 months ago)
- Language: Python
- Size: 1.95 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Usage
```python
..
from py4web_recaptcha import ReCaptchaV3Field
..@action("captcha_form", method=["GET", "POST"])
@action.uses("captcha_form.html", session)
def example_captcha_form():
def low_score_callback(score):
session.min_captcha_score = score
print("low_score_callback_called")def get_form(readonly=False):
print("generating_new_form")
extra_fields = []if hasattr(session, "min_captcha_score"):
min_score = session.min_captcha_score
extra_fields = [Field("email", requires=IS_EMAIL())]
else:
min_score = 1.0return Form(
[
Field("name", requires=IS_NOT_EMPTY()),
*extra_fields,
ReCaptchaV3Field(
name="captcha",
action="form1_submit",
min_score=min_score,
site_key="YOUR_SITE_KEY",
secret_key="YOUR_SECRET_KEY",
on_captcha_score_low=low_score_callback,
),
],
formstyle=FormStyleBulma,
readonly=readonly
)form = get_form()
message = ""
print("accepting/erroring form")
if form.accepted:
message = "form accepted with: %s " % (form.vars)
elif form.errors:
message = "form has errors: %s " % (form.errors)
if "captcha" in form.errors:
form = get_form(readonly=True)
form.readonly = False
form.errors['captcha'] = 'Bad score! We need some more info about you ...'
return dict(form=form, message=message)```