Sha256: 039da5d64b9f9fc1a943278e5bc76b1133e22977bf3c0d4b59447c418a20d97a

Contents?: true

Size: 963 Bytes

Versions: 17

Compression:

Stored size: 963 Bytes

Contents

/**
 * Module dependencies.
 */

var connect = require('../')
  , http = require('http');

var form = '\n\
  <form action="/" method="post">\n\
    <input type="hidden" name="_csrf" value="{token}" />\n\
    <input type="text" name="user[name]" value="{user}" placeholder="Username" />\n\
    <input type="submit" value="Login" />\n\
  </form>\n\
'; 

var app = connect()
  .use(connect.cookieParser())
  .use(connect.session({ secret: 'keyboard cat' }))
  .use(connect.bodyParser())
  .use(connect.csrf())
  .use(function(req, res, next){
    if ('POST' != req.method) return next();
    req.session.user = req.body.user;
    next();
  })
  .use(function(req, res){
    res.setHeader('Content-Type', 'text/html');
    var body = form
      .replace('{token}', req.csrfToken())
      .replace('{user}', req.session.user && req.session.user.name || '');
    res.end(body);
  });

http.createServer(app).listen(3000);
console.log('Server listening on port 3000');

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/examples/csrf.js