Skip to content

Commit

Permalink
Added callback (#12)
Browse files Browse the repository at this point in the history
* Updated to add callback option.

* Update flask_xcaptcha.py

* Update README.md
  • Loading branch information
greendoescode authored Apr 11, 2023
1 parent 4017f32 commit 633a962
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ XCAPTCHA_TABINDEX | Set the tabindex of the widget and popup | integer | 0 | O
XCAPTCHA_VERIFY_URL | The URL to verify the filled in xCaptcha at | URL | "https://www.google.com/recaptcha/api/siteverify" | Optional
XCAPTCHA_API_URL | The URL of the xCaptcha API JS script | URL | "//www.google.com/recaptcha/api.js" | Optional
XCAPTCHA_DIV_CLASS | The class of the div element surrounding the xCaptcha | string | "g-recaptcha" | Optional
XCAPTCHA_CALLBACK | The string that recaptcha finds on a button to see when a button is submitted | "OnSubmitCallback" | Optional

### In your template: `{{ xcaptcha }}`

Expand Down Expand Up @@ -157,4 +158,4 @@ Returns a bool indicating whether or not the xCaptcha was successfully completed

This will insert an HTML div element containing the captcha into a Jinja2 template

(c) 2022 Max Levine
(c) 2023 Max Levine
11 changes: 8 additions & 3 deletions flask_xcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""

__NAME__ = "Flask-xCaptcha"
__version__ = "0.5.4"
__version__ = "0.5.5"
__license__ = "MIT"
__author__ = "Max Levine"
__copyright__ = "(c) 2022 Max Levine"
__copyright__ = "(c) 2023 Max Levine"

try:
from flask import request
Expand All @@ -25,6 +25,7 @@ class DEFAULTS(object):
TYPE = "image"
SIZE = "normal"
TABINDEX = 0
CALLBACK = "onSubmitCallback"
VERIFY_URL = "https://www.google.com/recaptcha/api/siteverify"
API_URL = "//www.google.com/recaptcha/api.js"
DIV_CLASS = "g-recaptcha"
Expand All @@ -38,6 +39,7 @@ def __init__(self,
is_enabled=DEFAULTS.IS_ENABLED,
theme=DEFAULTS.THEME,
xtype=DEFAULTS.TYPE,
callback=DEFAULTS.CALLBACK,
size=DEFAULTS.SIZE,
tabindex=DEFAULTS.TABINDEX,
verify_url=DEFAULTS.VERIFY_URL,
Expand All @@ -51,6 +53,7 @@ def __init__(self,
self.is_enabled = app.config.get("XCAPTCHA_ENABLED", is_enabled)
self.theme = app.config.get("XCAPTCHA_THEME", theme)
self.type = app.config.get("XCAPTCHA_TYPE", xtype)
self.callback = app.config.get("XCAPTCHA_CALLBACK", callback)
self.size = app.config.get("XCAPTCHA_SIZE", size)
self.tabindex = app.config.get("XCAPTCHA_TABINDEX", tabindex)
self.verify_url = app.config.get("XCAPTCHA_VERIFY_URL", verify_url)
Expand All @@ -67,6 +70,7 @@ def get_code():
self.is_enabled = is_enabled
self.theme = theme
self.type = xtype
self.callback = callback
self.size = size
self.tabindex = tabindex
self.verify_url = verify_url
Expand All @@ -80,14 +84,15 @@ def get_code(self):
"""
return "" if not self.is_enabled else ("""
<script src='{API_URL}'></script>
<div class="{DIV_CLASS}" data-sitekey="{SITE_KEY}" data-theme="{THEME}" data-type="{TYPE}" data-size="{SIZE}"\
<div class="{DIV_CLASS}" data-sitekey="{SITE_KEY}" data-theme="{THEME}" data-type="{TYPE}" data-callback="{CALLBACK}" data-size="{SIZE}"\
data-tabindex="{TABINDEX}"></div>
""".format(
DIV_CLASS=self.div_class,
API_URL=self.api_url,
SITE_KEY=self.site_key,
THEME=self.theme,
TYPE=self.type,
CALLBACK=self.callback,
SIZE=self.size,
TABINDEX=self.tabindex
)
Expand Down

0 comments on commit 633a962

Please sign in to comment.