mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 10:16:12 +01:00
re: #2108, auth re-routing
This commit is contained in:
@@ -5,7 +5,8 @@ var async = require('async'),
|
||||
user = require('./user'),
|
||||
groups = require('./groups'),
|
||||
plugins = require('./plugins'),
|
||||
emitter = require('./emitter');
|
||||
emitter = require('./emitter'),
|
||||
auth = require('./routes/authentication');
|
||||
|
||||
(function (Meta) {
|
||||
Meta.restartRequired = false;
|
||||
@@ -36,7 +37,8 @@ var async = require('async'),
|
||||
async.parallel([
|
||||
async.apply(Meta.js.minify, false),
|
||||
async.apply(Meta.css.minify),
|
||||
async.apply(Meta.templates.compile)
|
||||
async.apply(Meta.templates.compile),
|
||||
async.apply(auth.reloadRoutes)
|
||||
], next);
|
||||
}
|
||||
], function(err) {
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
Password = require('../password'),
|
||||
winston = require('winston'),
|
||||
async = require('async'),
|
||||
express = require('express'),
|
||||
|
||||
meta = require('../meta'),
|
||||
user = require('../user'),
|
||||
plugins = require('../plugins'),
|
||||
db = require('../database'),
|
||||
hotswap = require('../hotswap'),
|
||||
utils = require('../../public/src/utils'),
|
||||
|
||||
login_strategies = [];
|
||||
login_strategies = [],
|
||||
controllers = require('../controllers');
|
||||
|
||||
function logout(req, res) {
|
||||
if (req.user && parseInt(req.user.uid, 10) > 0) {
|
||||
@@ -140,17 +143,21 @@
|
||||
app.use(passport.session());
|
||||
};
|
||||
|
||||
|
||||
Auth.get_login_strategies = function() {
|
||||
return login_strategies;
|
||||
};
|
||||
|
||||
Auth.registerApp = function(app) {
|
||||
Auth.registerApp = function(app, middleware) {
|
||||
Auth.app = app;
|
||||
Auth.middleware = middleware;
|
||||
};
|
||||
|
||||
Auth.createRoutes = function(app, middleware, controllers) {
|
||||
Auth.reloadRoutes = function(callback) {
|
||||
var router = express.Router();
|
||||
router.hotswapId = 'auth';
|
||||
|
||||
plugins.ready(function() {
|
||||
console.log('reloading auth routes!');
|
||||
plugins.fireHook('filter:auth.init', login_strategies, function(err) {
|
||||
if (err) {
|
||||
winston.error('filter:auth.init - plugin failure');
|
||||
@@ -173,12 +180,12 @@
|
||||
/* End backwards compatibility block */
|
||||
|
||||
if (strategy.url) {
|
||||
app.get(strategy.url, passport.authenticate(strategy.name, {
|
||||
router.get(strategy.url, passport.authenticate(strategy.name, {
|
||||
scope: strategy.scope
|
||||
}));
|
||||
}
|
||||
|
||||
app.get(strategy.callbackURL, passport.authenticate(strategy.name, {
|
||||
router.get(strategy.callbackURL, passport.authenticate(strategy.name, {
|
||||
successReturnToOrRedirect: nconf.get('relative_path') + '/',
|
||||
failureRedirect: nconf.get('relative_path') + '/login'
|
||||
}));
|
||||
@@ -198,9 +205,15 @@
|
||||
}
|
||||
/* End backwards compatibility block */
|
||||
|
||||
app.post('/logout', logout);
|
||||
app.post('/register', middleware.applyCSRF, register);
|
||||
app.post('/login', middleware.applyCSRF, login);
|
||||
router.post('/logout', logout);
|
||||
router.post('/register', Auth.middleware.applyCSRF, register);
|
||||
router.post('/login', Auth.middleware.applyCSRF, login);
|
||||
|
||||
hotswap.replace('auth', router);
|
||||
console.log('now I\m here,', typeof callback);
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -154,12 +154,16 @@ module.exports = function(app, middleware) {
|
||||
var router = express.Router(),
|
||||
pageRouter = express.Router(),
|
||||
pluginRouter = express.Router(),
|
||||
authRouter = express.Router(),
|
||||
relativePath = nconf.get('relative_path');
|
||||
|
||||
pluginRouter.render = function() {
|
||||
app.render.apply(app, arguments);
|
||||
};
|
||||
|
||||
// Set-up for hotswapping (when NodeBB reloads)
|
||||
pluginRouter.hotswapId = 'plugins';
|
||||
authRouter.hotswapId = 'auth';
|
||||
|
||||
app.all(relativePath + '/api/?*', middleware.prepareAPI);
|
||||
app.all(relativePath + '/api/admin/*', middleware.admin.isAdmin, middleware.prepareAPI);
|
||||
@@ -170,7 +174,6 @@ module.exports = function(app, middleware) {
|
||||
apiRoutes(router, middleware, controllers);
|
||||
feedRoutes(router, middleware, controllers);
|
||||
pluginRoutes(router, middleware, controllers);
|
||||
authRoutes.createRoutes(router, middleware, controllers);
|
||||
|
||||
app.use(relativePath, express.static(path.join(__dirname, '../../', 'public'), {
|
||||
maxAge: app.enabled('cache') ? 5184000000 : 0
|
||||
@@ -195,6 +198,7 @@ module.exports = function(app, middleware) {
|
||||
app.use(relativePath, router);
|
||||
app.use(relativePath, pluginRouter);
|
||||
app.use(relativePath, pageRouter);
|
||||
app.use(relativePath, authRouter);
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
require('./debug')(app, middleware, controllers);
|
||||
@@ -204,6 +208,7 @@ module.exports = function(app, middleware) {
|
||||
|
||||
// Add plugin routes
|
||||
plugins.reloadRoutes();
|
||||
authRoutes.reloadRoutes();
|
||||
};
|
||||
|
||||
function handleErrors(err, req, res, next) {
|
||||
|
||||
@@ -37,7 +37,6 @@ if(nconf.get('ssl')) {
|
||||
var port = nconf.get('PORT') || nconf.get('port');
|
||||
|
||||
logger.init(app);
|
||||
auth.registerApp(app);
|
||||
emailer.registerApp(app);
|
||||
|
||||
if (cluster.isWorker && process.env.handle_jobs === 'true') {
|
||||
@@ -64,6 +63,7 @@ if(nconf.get('ssl')) {
|
||||
middleware = middleware(app, data);
|
||||
routes(app, middleware);
|
||||
plugins.prepareApp(app, middleware);
|
||||
auth.registerApp(app, middleware);
|
||||
|
||||
if (err) {
|
||||
winston.error('Errors were encountered while attempting to initialise NodeBB.');
|
||||
|
||||
Reference in New Issue
Block a user