Skip to main content

Google ReCaptcha for Cherrypy.

Project description

Google ReCaptcha for cherrypy.

Installation

pip install marbaloo_recaptcha

Usage

# app.py
import cherrypy
import marbaloo_recaptcha
cherrypy.tools.recaptcha = marbaloo_recaptcha.Tool()


class Root(object):

    @cherrypy.expose
    def index(self, **kwargs):
        recaptcha = cherrypy.request.recaptcha
        if 'submit_recaptcha' in kwargs:
            if recaptcha.verify():
                return 'Success'
            else:
                return 'Fail'
        else:
            return '''
            <head>
                %s
            </head>
            <body>
                <form method="post">
                    %s
                    <input type="submit" name="submit_recaptcha"/>
                </form>
            </body>
            ''' % (recaptcha.get_html_head(), recaptcha.get_html_field(enable_no_script=True))

config = {
    'global': {
        "server.socket_host": "0.0.0.0",
        "server.socket_port": 9095,
    },
    '/': {
        'tools.recaptcha.on': True,
        'tools.recaptcha.remoteip': '',
        # For production level, uncomment this lines
        # 'tools.recaptcha.secret_key': 'MY_SECRET_KEY',
        # 'tools.recaptcha.site_key': 'MY_SITE_KEY',
    }
}
cherrypy.quickstart(Root(), '/', config)

Advanced Usage:

import cherrypy
import marbaloo_recaptcha
cherrypy.tools.recaptcha = marbaloo_recaptcha.Tool()


class Root(object):

    @cherrypy.expose
    def index(self, **kwargs):
        recaptcha = cherrypy.request.recaptcha
        if 'submit_recaptcha' in kwargs:
            if recaptcha.verify():
                return 'Success'
            else:
                return 'Fail'
        else:
            return '''
            <head>
                %s
            </head>
            <body>
                <form method="post">
                    %s
                    <input type="submit" name="submit_recaptcha"/>
                </form>
            </body>
            ''' % (recaptcha.get_html_head(defer=True,
                                           async=True,
                                           render='onload',
                                           onload='my_onload_javascript',
                                           hl='fa'),
                   recaptcha.get_html_field(data_attributes={
                                                                'data-theme': 'dark',
                                                                'data-size': 'compact',
                                                                'data-type': 'image'
                                                            },
                                            enable_no_script=True))

config = {
    'global': {
        "server.socket_host": "0.0.0.0",
        "server.socket_port": 9095,
    },
    '/': {
        'tools.recaptcha.on': True,
        'tools.recaptcha.remoteip': '',
        # For production level, uncomment this lines
        # 'tools.recaptcha.secret_key': 'MY_SECRET_KEY',
        # 'tools.recaptcha.site_key': 'MY_SITE_KEY',
    }
}
cherrypy.quickstart(Root(), '/', config)

Project details


Release history Release notifications

This version
History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
marbaloo_recaptcha-0.1.0.tar.gz (3.8 kB) Copy SHA256 hash SHA256 Source None Mar 12, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page