+
+
+
+
+ Check your answers before sending your application
+
+
+
+ When a user has entered data on pages, show it by using code like this:
+
+
+
+ {% raw %}
+ <tr>
+ <td>
+ Vehicle type:
+ </td>
+ <td>
+ {{vehicleType}}
+ </td>
+ </tr>
+ {% endraw %}
+
+
+
+
+
+
+
+
+
+{% endblock %}
diff --git a/app/views/examples/pass-data/vehicle-features.html b/app/views/examples/pass-data/vehicle-features.html
new file mode 100644
index 0000000000..51d5d674eb
--- /dev/null
+++ b/app/views/examples/pass-data/vehicle-features.html
@@ -0,0 +1,55 @@
+{% extends "layout.html" %}
+
+{% block page_title %}
+ Example - Passing data
+{% endblock %}
+
+{% block content %}
+
+
+
+ Data cleared
+
+
+
+ The session data has been cleared.
+
+
+
+
+ Prototype home page
+
+
+
+
+
+{% endblock %}
diff --git a/lib/utils.js b/lib/utils.js
index 9c1ab2f27f..aa0d30bfe6 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -95,3 +95,29 @@ exports.findAvailablePort = function(app){
});
}
+
+// Middleware - store any data sent in session, and pass it to all views
+
+exports.autoStoreData = function (req, res, next) {
+
+
+ if (!req.session.data){
+ req.session.data = {};
+ }
+
+ for (var i in req.body){
+ // any input where the name starts with _ is ignored
+ if (i.indexOf("_") != 0){
+ req.session.data[i] = req.body[i];
+ }
+ }
+
+ // send session data to all views
+
+ for (var i in req.session.data){
+ res.locals[i] = req.session.data[i];
+ }
+
+ next();
+
+}
diff --git a/package.json b/package.json
index df322c92b6..ccdec16bcf 100644
--- a/package.json
+++ b/package.json
@@ -16,11 +16,12 @@
"consolidate": "0.x",
"express": "4.13.3",
"express-nunjucks": "^0.9.3",
+ "express-session": "^1.13.0",
"express-writer": "0.0.4",
"govuk-elements-sass": "alphagov/govuk_elements#v1.1.1",
"govuk_frontend_toolkit": "^4.6.0",
- "govuk_template_mustache": "^0.16.4",
"govuk_template_jinja": "https://github.com/alphagov/govuk_template/releases/download/v0.16.4/jinja_govuk_template-0.16.4.tgz",
+ "govuk_template_mustache": "^0.16.4",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-concurrent": "0.4.3",
diff --git a/server.js b/server.js
index 1ba255880d..a70a14cfec 100644
--- a/server.js
+++ b/server.js
@@ -10,6 +10,7 @@ var path = require('path'),
port = (process.env.PORT || config.port),
utils = require(__dirname + '/lib/utils.js'),
packageJson = require(__dirname + '/package.json'),
+ session = require('express-session');
// Grab environment variables specified in Procfile or as Heroku config vars
releaseVersion = packageJson.version;
@@ -17,9 +18,11 @@ var path = require('path'),
password = process.env.PASSWORD,
env = process.env.NODE_ENV || 'development',
useAuth = process.env.USE_AUTH || config.useAuth;
+ useAutoStoreData = config.useAutoStoreData;
env = env.toLowerCase();
useAuth = useAuth.toLowerCase();
+ useAutoStoreData = useAutoStoreData.toLowerCase();
// Authenticate against the environment-provided credentials, if running
// the app in production (Heroku, effectively)
@@ -52,20 +55,31 @@ app.use(bodyParser.urlencoded({
extended: true
}));
-// send assetPath to all views
+// Support for session
+app.use(session({
+ secret: "prototype-kit",
+ resave: false,
+ saveUninitialized: false
+}));
+
app.use(function (req, res, next) {
+
+ // send assetPath to all views
res.locals.asset_path="/public/";
- next();
-});
-// Add variables that are available in all views
-app.use(function (req, res, next) {
+ // Add variables that are available in all views
res.locals.serviceName=config.serviceName;
res.locals.cookieText=config.cookieText;
res.locals.releaseVersion="v" + releaseVersion;
+
next();
+
});
+if (useAutoStoreData == 'true'){
+ app.use(utils.autoStoreData);
+}
+
// routes (found in app/routes.js)
if (typeof(routes) != "function"){
console.log(routes.bind);
@@ -75,6 +89,14 @@ if (typeof(routes) != "function"){
app.use("/", routes);
}
+app.get('/prototype-admin/clear-data', function(req, res){
+
+ req.session.destroy();
+
+ res.render("prototype-admin/clear-data");
+
+});
+
// auto render any view that exists
app.get(/^\/([^.]+)$/, function (req, res) {
@@ -97,6 +119,11 @@ app.get(/^\/([^.]+)$/, function (req, res) {
});
+// redirect all POSTs to GETs to avoid nasty refresh warning
+app.post(/^\/([^.]+)$/, function(req, res){
+ res.redirect("/" + req.params[0]);
+});
+
console.log("\nGOV.UK Prototype kit v" + releaseVersion);
// Display warning not to use kit for production services.
console.log("\nNOTICE: the kit is for building prototypes, do not use it for production services.");