JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11391
  • Score
    100M100P100Q123671F
  • License MIT

Google recaptcha middleware for express

Package Exports

  • express-recaptcha

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-recaptcha) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

express-recaptcha Build Status npm version

Google recaptcha middleware for express.

Link : https://www.google.com/recaptcha

installation

npm install express-recaptcha --save

Usage

Init

var recaptcha = require('express-recaptcha');
recaptcha.init('SITE_KEY', 'SECRET_KEY');
//or
recaptcha.init('SITE_KEY', 'SECRET_KEY', options);

options available properties

  • onload The callback function that gets called when all the dependencies have loaded.
  • render Value could be explicit OR onload, Whether to render the widget explicitly.
  • hl Forces the widget to render in a specific language.
  • theme Value could be dark OR light, The color theme of the widget (default light).
  • type Value could be audio OR image, The type of CAPTCHA to serve.
  • callback Your callback function that's executed when the user submits a successful CAPTCHA response.

For more explanations, please refer to the documentation https://developers.google.com/recaptcha/docs/display#config

Render

middleware render method set the recaptcha property of req object, with the generated html code.

Verify

middleware Verify method set the recaptcha property of req object, with validation informations.

{
    success: bool, //could be true or false
    error: string //error code (see below)
}
Error code Description
missing-input-secret The secret parameter is missing.
invalid-input-secret The secret parameter is invalid or malformed.
missing-input-response The response parameter is missing.
invalid-input-response The response parameter is invalid or malformed.

Example

var express = require('express');
var pub = __dirname + '/public';
var app = express();
var recaptcha = require('express-recaptcha');

recaptcha.init('SITE_KEY', 'SECRET_KEY');

app.use(express.static(pub));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

app.get('/', recaptcha.middleware.render, function(req, res){
  res.render('login', { captcha:req.recaptcha });
});

app.post('/', recaptcha.middleware.verify, function(req, res){
    if (req.recaptcha.success)
        // success code
    else
        // error code
});

Example - without middleware

var express = require('express');
var pub = __dirname + '/public';
var app = express();
var recaptcha = require('express-recaptcha');

recaptcha.init('SITE_KEY', 'SECRET_KEY');

app.use(express.static(pub));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

app.get('/', function(req, res){
  res.render('login', { captcha:recaptcha.render() });
});

app.post('/', function(req, res){
    recaptcha.verify(req, function(success,error){
        if(success)
            //success code
        else
            //error code
    }
});