|
|
|
@ -14,32 +14,8 @@
|
|
|
|
|
|
|
|
|
|
login_strategies = [];
|
|
|
|
|
|
|
|
|
|
plugins.ready(function() {
|
|
|
|
|
plugins.fireHook('filter:auth.init', login_strategies, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('filter:auth.init - plugin failure');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Auth.createRoutes(Auth.app);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Auth.initialize = function(app) {
|
|
|
|
|
app.use(passport.initialize());
|
|
|
|
|
app.use(passport.session());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Auth.get_login_strategies = function() {
|
|
|
|
|
return login_strategies;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Auth.registerApp = function(app) {
|
|
|
|
|
Auth.app = app;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Auth.createRoutes = function(app) {
|
|
|
|
|
app.post('/logout', function(req, res) {
|
|
|
|
|
function logout(req, res) {
|
|
|
|
|
if (req.user && parseInt(req.user.uid, 10) > 0) {
|
|
|
|
|
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
|
|
|
|
|
|
|
|
|
@ -50,23 +26,9 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res.send(200);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (var i in login_strategies) {
|
|
|
|
|
if (login_strategies.hasOwnProperty(i)) {
|
|
|
|
|
var strategy = login_strategies[i];
|
|
|
|
|
app.get(strategy.url, passport.authenticate(strategy.name, {
|
|
|
|
|
scope: strategy.scope
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
app.get(strategy.callbackURL, passport.authenticate(strategy.name, {
|
|
|
|
|
successRedirect: '/',
|
|
|
|
|
failureRedirect: '/login'
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.post('/login', function(req, res, next) {
|
|
|
|
|
function login(req, res, next) {
|
|
|
|
|
passport.authenticate('local', function(err, userData, info) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
@ -96,9 +58,9 @@
|
|
|
|
|
res.json(200, info);
|
|
|
|
|
});
|
|
|
|
|
})(req, res, next);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.post('/register', function(req, res) {
|
|
|
|
|
function register(req, res) {
|
|
|
|
|
if(meta.config.allowRegistration !== undefined && parseInt(meta.config.allowRegistration, 10) === 0) {
|
|
|
|
|
return res.send(403);
|
|
|
|
|
}
|
|
|
|
@ -121,6 +83,47 @@
|
|
|
|
|
res.redirect(nconf.get('relative_path') + '/register');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Auth.initialize = function(app) {
|
|
|
|
|
app.use(passport.initialize());
|
|
|
|
|
app.use(passport.session());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Auth.get_login_strategies = function() {
|
|
|
|
|
return login_strategies;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Auth.registerApp = function(app) {
|
|
|
|
|
Auth.app = app;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Auth.createRoutes = function(app, middleware, controllers) {
|
|
|
|
|
plugins.ready(function() {
|
|
|
|
|
plugins.fireHook('filter:auth.init', login_strategies, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('filter:auth.init - plugin failure');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i in login_strategies) {
|
|
|
|
|
if (login_strategies.hasOwnProperty(i)) {
|
|
|
|
|
var strategy = login_strategies[i];
|
|
|
|
|
app.get(strategy.url, passport.authenticate(strategy.name, {
|
|
|
|
|
scope: strategy.scope
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
app.get(strategy.callbackURL, passport.authenticate(strategy.name, {
|
|
|
|
|
successRedirect: '/',
|
|
|
|
|
failureRedirect: '/login'
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.post('/logout', logout);
|
|
|
|
|
app.post('/login', login);
|
|
|
|
|
app.post('/register', register);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|