diff --git a/src/middleware/admin.js b/src/middleware/admin.js index 92ab6de9e2..3cef701d08 100644 --- a/src/middleware/admin.js +++ b/src/middleware/admin.js @@ -16,7 +16,9 @@ var app, middleware.isAdmin = function(req, res, next) { if (!req.user) { - return res.redirect(nconf.get('relative_path') + '/login?next=admin'); + return res.json(404, { + error: 'not-found' + }); } user.isAdministrator((req.user && req.user.uid) ? req.user.uid : 0, function (err, isAdmin) { diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 296a445ca4..aa1e6dec61 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -15,6 +15,7 @@ var app, categories = require('./../categories'), topics = require('./../topics'), messaging = require('../messaging'), + ensureLoggedIn = require('connect-ensure-login'), controllers = { api: require('./../controllers/api') @@ -32,6 +33,8 @@ middleware.authenticate = function(req, res, next) { } }; +middleware.ensureLoggedIn = ensureLoggedIn.ensureLoggedIn(); + middleware.updateLastOnlineTime = function(req, res, next) { if(req.user) { user.updateLastOnlineTime(req.user.uid); diff --git a/src/routes/authentication.js b/src/routes/authentication.js index e39e72ba3c..9841f3c69d 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -177,7 +177,7 @@ } app.get(strategy.callbackURL, passport.authenticate(strategy.name, { - successRedirect: nconf.get('relative_path') + '/', + successReturnToOrRedirect: nconf.get('relative_path') + '/', failureRedirect: nconf.get('relative_path') + '/login' })); } diff --git a/src/routes/index.js b/src/routes/index.js index 01b095a092..47c67c3457 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -163,7 +163,7 @@ module.exports = function(app, middleware) { app.all(relativePath + '/api/?*', middleware.updateLastOnlineTime, middleware.prepareAPI); app.all(relativePath + '/api/admin/*', middleware.admin.isAdmin, middleware.prepareAPI); - app.all(relativePath + '/admin/?*', middleware.admin.isAdmin); + app.all(relativePath + '/admin/?*', middleware.ensureLoggedIn, middleware.admin.isAdmin); adminRoutes(router, middleware, controllers); metaRoutes(router, middleware, controllers);