Skip to content

Commit

Permalink
Major refactor of form parsing, submitted form data can now be valida…
Browse files Browse the repository at this point in the history
…ted back against the original form object (drupal style)
  • Loading branch information
cliftonc committed Apr 12, 2012
1 parent c6b03c9 commit c7fc565
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 149 deletions.
13 changes: 2 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var rootpath = process.cwd() + '/',
express = require('express'),
mongoose = require('mongoose'),
nodepath = require('path'),
form = require('connect-form'),
stylus = require('stylus'),
colors = require('colors'),
calipso = require(path.join(rootpath, 'lib/calipso')),
Expand Down Expand Up @@ -52,19 +51,16 @@ function bootApplication(next) {
app.config = new Config();
app.config.init();

app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.responseTime());

// Create dummy session middleware - tag it so we can later replace
var temporarySession = function(req, res, next) {
req.session = {};
next();
};
var temporarySession = express.session({ secret: "keyboard cat" });
temporarySession.tag = "session";
app.use(temporarySession);


// Default Theme
calipso.defaultTheme = app.config.get('themes:default');

Expand Down Expand Up @@ -105,11 +101,6 @@ function bootApplication(next) {
app.use(express["static"](path + '/media', {maxAge: 86400000}));
app.use(express["static"](path + '/lib/client/js', {maxAge: 86400000}));

// connect-form
app.use(form({
keepExtensions: app.config.get('libraries:formidable:keepExtensions')
}));

// Translation - after static, set to add mode if appropriate
app.use(translate.translate(app.config.get('i18n:language'), app.config.get('i18n:languages'), app.config.get('i18n:additive')));

Expand Down
21 changes: 2 additions & 19 deletions lib/calipso.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,8 @@ function router(app, initCallback) {
// Initialise helpers - first pass
calipso.getDynamicHelpers(req, res);

// Deal with any form content
// This is due to node-formidable / connect / express
// https://github.com/felixge/node-formidable/issues/30
// Best to parse the form very early in the chain
if(req.form) {

calipso.form.process(req, function() {

// Route the modules
calipso.module.eventRouteModules(req, res, next);

});

} else {

// Route the modules
calipso.module.eventRouteModules(req, res, next);

}
// Route the modules
calipso.module.eventRouteModules(req, res, next);

};
}
Expand Down
Loading

0 comments on commit c7fc565

Please sign in to comment.