From f03018b7ccc624b03fec3827db5c2b86d1adc96f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 21 Jun 2016 21:00:24 -0400 Subject: [PATCH] updated middlewares so if you have not completed registration, you will be required to do so --- src/middleware/middleware.js | 13 +++++++++++++ src/routes/helpers.js | 2 +- src/routes/index.js | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 7409bd1577..991f6bbe66 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -350,6 +350,19 @@ middleware.processTimeagoLocales = function(req, res, next) { } }; +middleware.registrationComplete = function(req, res, next) { + // If the user's session contains registration data, redirect the user to complete registration + if (!req.session.hasOwnProperty('registration')) { + return next(); + } else { + if (!req.path.endsWith('/register/complete')) { + controllers.helpers.redirect(res, '/register/complete'); + } else { + return next(); + } + } +}; + module.exports = function(webserver) { app = webserver; middleware.admin = require('./admin')(webserver); diff --git a/src/routes/helpers.js b/src/routes/helpers.js index 3dcca80bc4..378e2bdbc8 100644 --- a/src/routes/helpers.js +++ b/src/routes/helpers.js @@ -3,7 +3,7 @@ var helpers = {}; helpers.setupPageRoute = function(router, name, middleware, middlewares, controller) { - middlewares = middlewares.concat([middleware.pageView, middleware.pluginHooks]); + middlewares = middlewares.concat([middleware.registrationComplete, middleware.pageView, middleware.pluginHooks]); router.get(name, middleware.busyCheck, middleware.buildHeader, middlewares, controller); router.get('/api' + name, middlewares, controller); diff --git a/src/routes/index.js b/src/routes/index.js index 7266629e1a..d250524e24 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -28,7 +28,7 @@ function mainRoutes(app, middleware, controllers) { setupPageRoute(app, '/login', middleware, loginRegisterMiddleware, controllers.login); setupPageRoute(app, '/register', middleware, loginRegisterMiddleware, controllers.register); - setupPageRoute(app, '/register/complete', middleware, loginRegisterMiddleware, controllers.registerInterstitial); + setupPageRoute(app, '/register/complete', middleware, [], controllers.registerInterstitial); setupPageRoute(app, '/compose', middleware, [], controllers.compose); setupPageRoute(app, '/confirm/:code', middleware, [], controllers.confirmEmail); setupPageRoute(app, '/outgoing', middleware, [], controllers.outgoing);