backend logging

This commit is contained in:
root
2020-03-31 01:53:06 +02:00
parent 13822fcaba
commit 0313b1350c
3324 changed files with 23773 additions and 473711 deletions
+52
View File
@@ -0,0 +1,52 @@
/**
* Ensure that a user is logged in before proceeding to next route middleware.
*
* This middleware ensures that a user is logged in. If a request is received
* that is unauthenticated, the request will be redirected to a login page (by
* default to `/login`).
*
* Additionally, `returnTo` will be be set in the session to the URL of the
* current request. After authentication, this value can be used to redirect
* the user to the page that was originally requested.
*
* Options:
* - `redirectTo` URL to redirect to for login, defaults to _/login_
* - `setReturnTo` set redirectTo in session, defaults to _true_
*
* Examples:
*
* app.get('/profile',
* ensureLoggedIn(),
* function(req, res) { ... });
*
* app.get('/profile',
* ensureLoggedIn('/signin'),
* function(req, res) { ... });
*
* app.get('/profile',
* ensureLoggedIn({ redirectTo: '/session/new', setReturnTo: false }),
* function(req, res) { ... });
*
* @param {Object} options
* @return {Function}
* @api public
*/
module.exports = function ensureLoggedIn(options) {
if (typeof options == 'string') {
options = { redirectTo: options }
}
options = options || {};
var url = options.redirectTo || '/login';
var setReturnTo = (options.setReturnTo === undefined) ? true : options.setReturnTo;
return function(req, res, next) {
if (!req.isAuthenticated || !req.isAuthenticated()) {
if (setReturnTo && req.session) {
req.session.returnTo = req.originalUrl || req.url;
}
return res.redirect(url);
}
next();
}
}
+43
View File
@@ -0,0 +1,43 @@
/**
* Ensure that no user is logged in before proceeding to next route middleware.
*
* This middleware ensures that no user is logged in. If a request is received
* that is authenticated, the request will be redirected to another page (by
* default to `/`).
*
* Options:
* - `redirectTo` URL to redirect to in logged in, defaults to _/_
*
* Examples:
*
* app.get('/login',
* ensureLoggedOut(),
* function(req, res) { ... });
*
* app.get('/login',
* ensureLoggedOut('/home'),
* function(req, res) { ... });
*
* app.get('/login',
* ensureLoggedOut({ redirectTo: '/home' }),
* function(req, res) { ... });
*
* @param {Object} options
* @return {Function}
* @api public
*/
module.exports = function ensureLoggedOut(options) {
if (typeof options == 'string') {
options = { redirectTo: options }
}
options = options || {};
var url = options.redirectTo || '/';
return function(req, res, next) {
if (req.isAuthenticated && req.isAuthenticated()) {
return res.redirect(url);
}
next();
}
}
+10
View File
@@ -0,0 +1,10 @@
/**
* Expose middleware.
*/
exports.ensureAuthenticated =
exports.ensureLoggedIn = require('./ensureLoggedIn');
exports.ensureUnauthenticated =
exports.ensureNotAuthenticated =
exports.ensureLoggedOut =
exports.ensureNotLoggedIn = require('./ensureLoggedOut');