Coder Social home page Coder Social logo

zalew / django-recaptcha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from django-recaptcha/django-recaptcha

2.0 2.0 1.0 134 KB

Django reCAPTCHA form field/widget integration app. AJAX loaded forms support.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

django-recaptcha's Introduction

Django reCAPTCHA

Django reCAPTCHA form field/widget integration app.

django-recaptcha uses a modified version of the Python reCAPTCHA client which is included in the package as client.py.

  1. Install or add django-recaptcha to your Python path.

  2. Add captcha to your INSTALLED_APPS setting.

  3. Add a RECAPTCHA_PUBLIC_KEY setting to the project's settings.py file. This is your public API key as provided by reCAPTCHA, i.e.:

    RECAPTCHA_PUBLIC_KEY = '76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh'
    

    This can be seperately specified at runtime by passing a public_key parameter when constructing the ReCaptchaField, see field usage below.

  4. Add a RECAPTCHA_PRIVATE_KEY setting to the project's settings.py file. This is your private API key as provided by reCAPTCHA, i.e.:

    RECAPTCHA_PRIVATE_KEY = '98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs'
    

    This can be seperately specified at runtime by passing a private_key parameter when constructing the ReCaptchaField, see field usage below.

  5. Optionally add a RECAPTCHA_USE_SSL setting to the project's settings.py file. This causes reCAPTCHA validation submits to be made over SSL, i.e.:

    RECAPTCHA_USE_SSL = True
    

    If you don't add this setting the default behaviour is to NOT use SSL. This can be seperately specified at runtime by passing a use_ssl parameter when constructing the ReCaptchaField, see field usage below.

The quickest way to add reCAPTHCA to a form is to use the included ReCaptchaField field type. A ReCaptcha widget will be rendered with the field validating itself without any further action required from you. For example:

from django import forms
from captcha.fields import ReCaptchaField

class FormWithCaptcha(forms.Form):
    captcha = ReCaptchaField()

To allow for runtime specification of keys and SSL usage you can optionally pass private_key, public_key or use_ssl parameters to the constructor, i.e.:

captcha = ReCaptchaField(
    public_key='76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh',
    private_key='98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs',
    use_ssl=True
)

If specified these parameters will be used instead of your reCAPCTHA project settings.

The reCAPTCHA widget supports several Javascript options variables customizing the behaviour of the widget, such as theme and lang. You can forward these options to the widget by passing an attr parameter containing a dictionary of options to ReCaptchaField, i.e.:

captcha = ReCaptchaField(attrs={'theme' : 'clean'})

The captcha client takes the key/value pairs and writes out the RecaptchaOptions value in JavaScript.

django-recaptcha detects for DEBUG = True in the settings.py to facilitate unit tests. When DEBUG = TRUE, using PASSED as the recaptcha_response_field value.

Example:

form_params = {'recaptcha_response_field': 'PASSED'} form = RegistrationForm(form_params) # assuming only one ReCaptchaField form.is_valid() # True

Passing any other values will cause django-recaptcha to continue normal processing and return a form error.

django-recaptcha ships with a django-registration backend extending the default backend to include a reCAPTCHA field. This is included mostly as an example of how you could intergrate a reCAPTCHA field with django-registration. I suggest you familiarize yourself with the django-registration docs for more comprehensive documentation.

Note

This backend will only work with django-registration versions 0.8-alpha-1 and up.

To use the reCAPTHCA backend complete these steps:

  1. Add registration to your INSTALLED_APPS setting.

  2. Add captcha registration backend url include to your project's urls.py file:

    (r'^accounts/', include('captcha.backends.default.urls')),
    
  3. Add an ACCOUNT_ACTIVATION_DAYS setting to the project's settings.py file. This is the number of days users will have to activate their accounts after registering, as required by django-registration, i.e.:

    ACCOUNT_ACTIVATION_DAYS = 7
    
  4. Implement the various templates as required by django-registration.

Once done you should be able to access /accounts/register/ and see the reCAPTCHA field in action as part of the registration process.

To make Recapcha work in ajax-loaded forms:

  1. import recaptcha_ajax.js on your page (not in the loaded template):

    <script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>

  2. settings.py

    CAPTCHA_AJAX = True

Inspired Marco Fucci's blogpost titled Integrating reCAPTCHA with Django

client.py taken from recaptcha-client licenced MIT/X11 by Mike Crawford.

reCAPTCHA copyright 2011 Google.

django-recaptcha's People

Contributors

denz avatar hedleyroos avatar joejasinski avatar victorneo avatar zalew avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

fu2re

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.