Flask-xCaptcha


NameFlask-xCaptcha JSON
Version 0.5.5 PyPI version JSON
download
home_pagehttps://github.com/bmaximuml/flask-xcaptcha
SummaryThe new xCaptcha implementation for Flask without Flask-WTF
upload_time2023-04-11 20:10:34
maintainer
docs_urlNone
authorMax Levine
requires_python
licenseMIT
keywords flask recaptcha hcaptcha xcaptcha validate
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # Flask-xCaptcha

[![Build Status](https://app.travis-ci.com/bmaximuml/flask-xcaptcha.svg?branch=master)](https://app.travis-ci.com/bmaximuml/flask-xcaptcha)

The new xCaptcha implementation for Flask without Flask-WTF.

Can also be used as standalone

Compatible with:

* Google ReCaptcha (default)
* hCaptcha
* Any other similarly configured captcha

This project was forked from [Mardix's Flask-ReCaptcha](https://github.com/mardix/flask-recaptcha) project

---

## Installation

`pip install flask-xcaptcha`

## Usage - Minimal Implementation

### Google ReCaptcha - Using app variable

```python
from flask import Flask
from flask_xcaptcha import XCaptcha

app = Flask(__name__)
app.config.update(
    XCAPTCHA_SITE_KEY=#<your_site_key>,
    XCAPTCHA_SECRET_KEY=#<your_secret_key>
)
xcaptcha = XCaptcha(app=app)
```

### Google ReCaptcha - Without app variable

```python
from flask_xcaptcha import XCaptcha

xcaptcha = XCaptcha(
    site_key=#<your_site_key>,
    secret_key=#<your_secret_key>
)
```

### hCaptcha - Using app variable

```python
from flask import Flask
from flask_xcaptcha import XCaptcha

app = Flask(__name__)
app.config.update(
    XCAPTCHA_SITE_KEY=#<your_site_key>,
    XCAPTCHA_SECRET_KEY=#<your_secret_key>,
    XCAPTCHA_VERIFY_URL=https://hcaptcha.com/siteverify,
    XCAPTCHA_API_URL=https://hcaptcha.com/1/api.js,
    XCAPTCHA_DIV_CLASS=h-captcha
)
xcaptcha = XCaptcha(app=app)
```

### hCaptcha - Without app variable

```python
from flask_xcaptcha import XCaptcha

xcaptcha = XCaptcha(
    site_key=#<your_site_key>,
    secret_key=#<your_secret_key>,
    verify_url=https://hcaptcha.com/siteverify,
    api_url=https://hcaptcha.com/1/api.js,
    div_class=h-captcha
)
```

### App Config Variables

Flask-xCaptcha is configured through the standard Flask config API.
Add these to your app config as shown above to further configure your xCaptcha

Variable            | Description | Allowed Values | Default | Required?
---                 | ---         | ---            | ---     | ---
XCAPTCHA_SITE_KEY   | Site key provided by xCaptcha service | Your site key | | Required
XCAPTCHA_SECRET_KEY | Secret key provided by xCaptcha service | Your secret key | | Required
XCAPTCHA_ENABLED    | Enable verification. If false, verification will be disabled | True / False | True | Optional
XCAPTCHA_THEME      | Theme for the xCaptcha element | light / dark (service dependent) | "light" | Optional
XCAPTCHA_TYPE       | Type of xCaptcha | service dependent | "image" | Optional
XCAPTCHA_SIZE       | Size of xCaptcha | normal / compact (service dependent) | "normal" | Optional
XCAPTCHA_TABINDEX   | Set the tabindex of the widget and popup | integer | 0 | Optional
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 }}`

Inside of the form you want to protect, include the tag: `{{ xcaptcha }}`

It will insert the code automatically

```html
<form method="post" action="/submit">
    ... your field
    ... your field

    {{ xcaptcha }}

    [submit button]
</form>
```

### Verify the captcha

In the view that's going to validate the captcha

```python
from flask import Flask
from flask_xcaptcha import XCaptcha

app = Flask(__name__)
app.config.update(
    XCAPTCHA_SITE_KEY=#<your_site_key>,
    XCAPTCHA_SECRET_KEY=#<your_secret_key>
)
xcaptcha = XCaptcha(app=app)

@route("/submit", methods=["POST"])
def submit():

    if xcaptcha.verify():
        # SUCCESS
        pass
    else:
        # FAILED
        pass
```

## API

### XCaptcha.__init__(app=None, site_key=None, secret_key=None, is_enabled=True, theme="light", xtype="image", size="normal", tabindex=0, verify_url="https://www.google.com/recaptcha/api/siteverify", api_url="//www.google.com/recaptcha/api.js", div_class="g-recaptcha",**kwargs)

Initialises the XCaptcha using values set in the app config (if an app is supplied), and otherwise using directly passed arguments

### XCaptcha.get_code()

Returns the HTML code to replace `{{ xcaptcha }}` with.

### XCaptcha.verify()

Returns a bool indicating whether or not the xCaptcha was successfully completed

## `{{ xcaptcha }}`

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

(c) 2023 Max Levine

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bmaximuml/flask-xcaptcha",
    "name": "Flask-xCaptcha",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "flask,recaptcha,hcaptcha,xcaptcha,validate",
    "author": "Max Levine",
    "author_email": "max@maxlevine.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/47/c2/b76f37eec67f7d59933307279f8dccf6cae913897ca63222094556fa9fbf/Flask-xCaptcha-0.5.5.tar.gz",
    "platform": "any",
    "description": "# Flask-xCaptcha\n\n[![Build Status](https://app.travis-ci.com/bmaximuml/flask-xcaptcha.svg?branch=master)](https://app.travis-ci.com/bmaximuml/flask-xcaptcha)\n\nThe new xCaptcha implementation for Flask without Flask-WTF.\n\nCan also be used as standalone\n\nCompatible with:\n\n* Google ReCaptcha (default)\n* hCaptcha\n* Any other similarly configured captcha\n\nThis project was forked from [Mardix's Flask-ReCaptcha](https://github.com/mardix/flask-recaptcha) project\n\n---\n\n## Installation\n\n`pip install flask-xcaptcha`\n\n## Usage - Minimal Implementation\n\n### Google ReCaptcha - Using app variable\n\n```python\nfrom flask import Flask\nfrom flask_xcaptcha import XCaptcha\n\napp = Flask(__name__)\napp.config.update(\n    XCAPTCHA_SITE_KEY=#<your_site_key>,\n    XCAPTCHA_SECRET_KEY=#<your_secret_key>\n)\nxcaptcha = XCaptcha(app=app)\n```\n\n### Google ReCaptcha - Without app variable\n\n```python\nfrom flask_xcaptcha import XCaptcha\n\nxcaptcha = XCaptcha(\n    site_key=#<your_site_key>,\n    secret_key=#<your_secret_key>\n)\n```\n\n### hCaptcha - Using app variable\n\n```python\nfrom flask import Flask\nfrom flask_xcaptcha import XCaptcha\n\napp = Flask(__name__)\napp.config.update(\n    XCAPTCHA_SITE_KEY=#<your_site_key>,\n    XCAPTCHA_SECRET_KEY=#<your_secret_key>,\n    XCAPTCHA_VERIFY_URL=https://hcaptcha.com/siteverify,\n    XCAPTCHA_API_URL=https://hcaptcha.com/1/api.js,\n    XCAPTCHA_DIV_CLASS=h-captcha\n)\nxcaptcha = XCaptcha(app=app)\n```\n\n### hCaptcha - Without app variable\n\n```python\nfrom flask_xcaptcha import XCaptcha\n\nxcaptcha = XCaptcha(\n    site_key=#<your_site_key>,\n    secret_key=#<your_secret_key>,\n    verify_url=https://hcaptcha.com/siteverify,\n    api_url=https://hcaptcha.com/1/api.js,\n    div_class=h-captcha\n)\n```\n\n### App Config Variables\n\nFlask-xCaptcha is configured through the standard Flask config API.\nAdd these to your app config as shown above to further configure your xCaptcha\n\nVariable            | Description | Allowed Values | Default | Required?\n---                 | ---         | ---            | ---     | ---\nXCAPTCHA_SITE_KEY   | Site key provided by xCaptcha service | Your site key | | Required\nXCAPTCHA_SECRET_KEY | Secret key provided by xCaptcha service | Your secret key | | Required\nXCAPTCHA_ENABLED    | Enable verification. If false, verification will be disabled | True / False | True | Optional\nXCAPTCHA_THEME      | Theme for the xCaptcha element | light / dark (service dependent) | \"light\" | Optional\nXCAPTCHA_TYPE       | Type of xCaptcha | service dependent | \"image\" | Optional\nXCAPTCHA_SIZE       | Size of xCaptcha | normal / compact (service dependent) | \"normal\" | Optional\nXCAPTCHA_TABINDEX   | Set the tabindex of the widget and popup | integer | 0 | Optional\nXCAPTCHA_VERIFY_URL | The URL to verify the filled in xCaptcha at | URL | \"https://www.google.com/recaptcha/api/siteverify\" | Optional\nXCAPTCHA_API_URL    | The URL of the xCaptcha API JS script | URL | \"//www.google.com/recaptcha/api.js\" | Optional\nXCAPTCHA_DIV_CLASS  | The class of the div element surrounding the xCaptcha | string | \"g-recaptcha\" | Optional\nXCAPTCHA_CALLBACK   | The string that recaptcha finds on a button to see when a button is submitted | \"OnSubmitCallback\" | Optional\n\n### In your template: `{{ xcaptcha }}`\n\nInside of the form you want to protect, include the tag: `{{ xcaptcha }}`\n\nIt will insert the code automatically\n\n```html\n<form method=\"post\" action=\"/submit\">\n    ... your field\n    ... your field\n\n    {{ xcaptcha }}\n\n    [submit button]\n</form>\n```\n\n### Verify the captcha\n\nIn the view that's going to validate the captcha\n\n```python\nfrom flask import Flask\nfrom flask_xcaptcha import XCaptcha\n\napp = Flask(__name__)\napp.config.update(\n    XCAPTCHA_SITE_KEY=#<your_site_key>,\n    XCAPTCHA_SECRET_KEY=#<your_secret_key>\n)\nxcaptcha = XCaptcha(app=app)\n\n@route(\"/submit\", methods=[\"POST\"])\ndef submit():\n\n    if xcaptcha.verify():\n        # SUCCESS\n        pass\n    else:\n        # FAILED\n        pass\n```\n\n## API\n\n### XCaptcha.__init__(app=None, site_key=None, secret_key=None, is_enabled=True, theme=\"light\", xtype=\"image\", size=\"normal\", tabindex=0, verify_url=\"https://www.google.com/recaptcha/api/siteverify\", api_url=\"//www.google.com/recaptcha/api.js\", div_class=\"g-recaptcha\",**kwargs)\n\nInitialises the XCaptcha using values set in the app config (if an app is supplied), and otherwise using directly passed arguments\n\n### XCaptcha.get_code()\n\nReturns the HTML code to replace `{{ xcaptcha }}` with.\n\n### XCaptcha.verify()\n\nReturns a bool indicating whether or not the xCaptcha was successfully completed\n\n## `{{ xcaptcha }}`\n\nThis will insert an HTML div element containing the captcha into a Jinja2 template\n\n(c) 2023 Max Levine\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "The new xCaptcha implementation for Flask without Flask-WTF",
    "version": "0.5.5",
    "split_keywords": [
        "flask",
        "recaptcha",
        "hcaptcha",
        "xcaptcha",
        "validate"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d1a1e5ca66fb727925ac0ecb9b36dd7e047e7049b991a91abdfd08f8e8cf0207",
                "md5": "1d6263fc49f01e991fdb132cbae6e1d8",
                "sha256": "ff8fc70a26048e6668bd7a450dcf31ca4f49cacc7d5556d47dc7e3557016e8cf"
            },
            "downloads": -1,
            "filename": "Flask_xCaptcha-0.5.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1d6263fc49f01e991fdb132cbae6e1d8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5254,
            "upload_time": "2023-04-11T20:10:32",
            "upload_time_iso_8601": "2023-04-11T20:10:32.665036Z",
            "url": "https://files.pythonhosted.org/packages/d1/a1/e5ca66fb727925ac0ecb9b36dd7e047e7049b991a91abdfd08f8e8cf0207/Flask_xCaptcha-0.5.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47c2b76f37eec67f7d59933307279f8dccf6cae913897ca63222094556fa9fbf",
                "md5": "be4b8e2d6670d911be53e4fc3a7b7022",
                "sha256": "8d1c0bfcf70ee10630e11636875dd51bd5e4e20fed339068cf19a101d5a9180e"
            },
            "downloads": -1,
            "filename": "Flask-xCaptcha-0.5.5.tar.gz",
            "has_sig": false,
            "md5_digest": "be4b8e2d6670d911be53e4fc3a7b7022",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5391,
            "upload_time": "2023-04-11T20:10:34",
            "upload_time_iso_8601": "2023-04-11T20:10:34.753475Z",
            "url": "https://files.pythonhosted.org/packages/47/c2/b76f37eec67f7d59933307279f8dccf6cae913897ca63222094556fa9fbf/Flask-xCaptcha-0.5.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-11 20:10:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "bmaximuml",
    "github_project": "flask-xcaptcha",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flask-xcaptcha"
}
        
Elapsed time: 0.06458s