crcaptcha

1.0.1 • Public • Published

node-crcaptcha

Renders and checks the Civil Rights Captcha.

Installation

$ npm install crcaptcha

Library

crcaptcha.show(callback(err, captchaHtml), lang = en)

Requests a captcha form. The two languages currently supported are Swedish (sv) and English (en.)


crcaptcha.check(code, sessid, callback(err, success))

Verify a captcha.

Example using Express

app.js:

var express = require("express")
    , http = require("http")
    , crc = require("../lib/crcaptcha");

var app = express();

app.configure(function(){
    app.set("port", process.env.PORT || 3000);
    app.set("views", __dirname + "/views");
    app.set("view engine", "jade");
    app.use(express.favicon());
    app.use(express.logger("dev"));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
});

app.configure("development", function(){
    app.use(express.errorHandler());
});

app.get("/", function(req, res) {
    crc.show(function (err, html) {
        if (err) {
            console.log(err);
        } else {
            res.render("form", { captcha: html });
        }
    });
});

app.post("/", function (req, res) {
    crc.check(req.body.crc_captcha, req.body.crc_sessid, function (err, success) {
        if (err) {
            console.log(err);
        } else {
            if (success) {
                res.send("Right.");
            } else {
                res.send("Wrong.");
            }
        }
    });
});

http.createServer(app).listen(app.get("port"), function(){
    console.log("Express server listening on port " + app.get("port"));
});

views/form.jade:

!!! 5
html
  head
    script(src="http://code.jquery.com/jquery-latest.min.js", type="text/javascript")
  body
    form(method='POST', action='/')
      != captcha
      input(type='submit', value='Check Civil Rights Captcha')

Readme

Keywords

none

Package Sidebar

Install

npm i crcaptcha

Weekly Downloads

1

Version

1.0.1

License

none

Last publish

Collaborators

  • olahol