|
|
@ -198,49 +198,44 @@ module.exports = function (middleware) {
|
|
|
|
], next);
|
|
|
|
], next);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
middleware.isAdmin = function isAdmin(req, res, next) {
|
|
|
|
middleware.isAdmin = async function isAdmin(req, res, next) {
|
|
|
|
async.waterfall([
|
|
|
|
const isAdmin = await user.isAdministrator(req.uid);
|
|
|
|
function (next) {
|
|
|
|
if (!isAdmin) {
|
|
|
|
user.isAdministrator(req.uid, next);
|
|
|
|
controllers.helpers.notAllowed(req, res);
|
|
|
|
},
|
|
|
|
return;
|
|
|
|
function (isAdmin, next) {
|
|
|
|
}
|
|
|
|
if (!isAdmin) {
|
|
|
|
const hasPassword = await user.hasPassword(req.uid);
|
|
|
|
return controllers.helpers.notAllowed(req, res);
|
|
|
|
if (!hasPassword) {
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
user.hasPassword(req.uid, next);
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
function (hasPassword, next) {
|
|
|
|
|
|
|
|
if (!hasPassword) {
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var loginTime = req.session.meta ? req.session.meta.datetime : 0;
|
|
|
|
const loginTime = req.session.meta ? req.session.meta.datetime : 0;
|
|
|
|
var adminReloginDuration = meta.config.adminReloginDuration * 60000;
|
|
|
|
const adminReloginDuration = meta.config.adminReloginDuration * 60000;
|
|
|
|
var disabled = meta.config.adminReloginDuration === 0;
|
|
|
|
const disabled = meta.config.adminReloginDuration === 0;
|
|
|
|
if (disabled || (loginTime && parseInt(loginTime, 10) > Date.now() - adminReloginDuration)) {
|
|
|
|
if (disabled || (loginTime && parseInt(loginTime, 10) > Date.now() - adminReloginDuration)) {
|
|
|
|
var timeLeft = parseInt(loginTime, 10) - (Date.now() - adminReloginDuration);
|
|
|
|
const timeLeft = parseInt(loginTime, 10) - (Date.now() - adminReloginDuration);
|
|
|
|
if (req.session.meta && timeLeft < Math.min(300000, adminReloginDuration)) {
|
|
|
|
if (req.session.meta && timeLeft < Math.min(300000, adminReloginDuration)) {
|
|
|
|
req.session.meta.datetime += Math.min(300000, adminReloginDuration);
|
|
|
|
req.session.meta.datetime += Math.min(300000, adminReloginDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return next();
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var returnTo = req.path;
|
|
|
|
let returnTo = req.path;
|
|
|
|
if (nconf.get('relative_path')) {
|
|
|
|
if (nconf.get('relative_path')) {
|
|
|
|
returnTo = req.path.replace(new RegExp('^' + nconf.get('relative_path')), '');
|
|
|
|
returnTo = req.path.replace(new RegExp('^' + nconf.get('relative_path')), '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
returnTo = returnTo.replace(/^\/api/, '');
|
|
|
|
returnTo = returnTo.replace(/^\/api/, '');
|
|
|
|
|
|
|
|
|
|
|
|
req.session.returnTo = returnTo;
|
|
|
|
req.session.returnTo = returnTo;
|
|
|
|
req.session.forceLogin = 1;
|
|
|
|
req.session.forceLogin = 1;
|
|
|
|
if (res.locals.isAPI) {
|
|
|
|
if (res.locals.isAPI) {
|
|
|
|
res.status(401).json({});
|
|
|
|
res.status(401).json({});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.redirect(nconf.get('relative_path') + '/login?local=1');
|
|
|
|
res.redirect(nconf.get('relative_path') + '/login?local=1');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
], next);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
middleware.requireUser = function (req, res, next) {
|
|
|
|
middleware.requireUser = function (req, res, next) {
|
|
|
|