From 041670bfe99255ef2b49b00c9464761d06160d1b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 22 Jun 2016 14:40:34 -0400 Subject: [PATCH] handling of form completion in registration interstitial --- src/controllers/authentication.js | 31 +++++++++++++++++++++++++++++-- src/controllers/index.js | 4 ++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index 2879691dd1..180c9e57c4 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -129,8 +129,35 @@ function addToApprovalQueue(req, userData, callback) { } authenticationController.registerComplete = function(req, res, next) { - console.log(req.data); - res.sendStatus(200); + // For the interstitials that respond, execute the callback with the form body + plugins.fireHook('filter:register.interstitial', { + userData: req.session.registration, + interstitials: [] + }, function(err, data) { + var callbacks = data.interstitials.reduce(function(memo, cur) { + if (cur.hasOwnProperty('callback') && typeof cur.callback === 'function') { + memo.push(async.apply(cur.callback, req.session.registration, req.body)); + } + + return memo; + }, []); + + async.parallel(callbacks, function(err) { + if (err) { + req.flash('error', err.message); + return res.redirect(nconf.get('relative_path') + '/register/complete'); + } + + // Clear registration data in session + delete req.session.registration; + + if (req.session.returnTo) { + res.redirect(req.session.returnTo); + } else { + res.redirect(nconf.get('relative_path') + '/'); + } + }); + }); }; authenticationController.login = function(req, res, next) { diff --git a/src/controllers/index.js b/src/controllers/index.js index a18f3695d5..5906b36285 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -194,6 +194,10 @@ Controllers.registerInterstitial = function(req, res, next) { userData: req.session.registration, interstitials: [] }, function(err, data) { + if (!data.interstitials.length) { + return next(); + } + var renders = data.interstitials.map(function(interstitial) { return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data) });