Giter Site home page Giter Site logo

re-captcha's Introduction

re-captcha Build Status

recaptcha renders and verifies Recaptcha captchas.

Installation

Via npm:

npm install re-captcha

Setup

Before you can use this module, you must visit http://www.google.com/recaptcha to request a public and private API key for your domain.

Customizing the Recaptcha

See these instructions for help customizing the look of Recaptcha. In brief, you will need to add a structure like the following before the form in your document:

<script>
  var RecaptchaOptions = {
   theme: 'clean',
   lang: 'en'
  };
</script>

Example Using Connect/Express

app.js:

var express  = require('connect');
var Recaptcha = require('re-captcha');

var PUBLIC_KEY  = 'YOUR_PUBLIC_KEY';
var PRIVATE_KEY = 'YOUR_PRIVATE_KEY';
var recaptcha = new Recaptcha(PUBLIC_KEY, PRIVATE_KEY);

var app = connect();
app.use(connect.bodyParser());
app.get('/', function(req, res) {
  res.render('index', {
    layout: false,
    locals: {
      recaptcha_form: recaptcha.toHTML()
    }
  });
});

app.post('/', function(req, res) {
  var data = {
    remoteip:  req.connection.remoteAddress,
    challenge: req.body.recaptcha_challenge_field,
    response:  req.body.recaptcha_response_field
  };

  recaptcha.verify(data, function(err) {
    if (err) {
      // Redisplay the form.
      res.render('form.html', {
        layout: false,
        locals: {
          recaptcha_form: recaptcha.toHTML(err)
        }
      });
    } else {
      res.send('Recaptcha response valid.');
    }
  });
});

http.createServer(app).listen(3000);

views/form.html:

<form method="POST" action=".">
  <%-recaptcha_form%>
  <input type="submit">
</form>

Make sure connect and EJS are installed, then:

$ node app.js

re-captcha's People

Contributors

mirhampt avatar jacksontian avatar robertkowalski avatar gsmcwhirter avatar osher avatar

Watchers

 avatar

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.