2016-09-30 14:45:59 +03:00
|
|
|
var errors = require('../errors'),
|
|
|
|
labs = require('../utils/labs'),
|
|
|
|
i18n = require('../i18n'),
|
|
|
|
authorize;
|
|
|
|
|
|
|
|
authorize = {
|
|
|
|
// Workaround for missing permissions
|
|
|
|
// TODO: rework when https://github.com/TryGhost/Ghost/issues/3911 is done
|
|
|
|
requiresAuthorizedUser: function requiresAuthorizedUser(req, res, next) {
|
|
|
|
if (req.user && req.user.id) {
|
|
|
|
return next();
|
|
|
|
} else {
|
2016-10-06 15:27:35 +03:00
|
|
|
return next(new errors.NoPermissionError({message: i18n.t('errors.middleware.auth.pleaseSignIn')}));
|
2016-09-30 14:45:59 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// ### Require user depending on public API being activated.
|
|
|
|
requiresAuthorizedUserPublicAPI: function requiresAuthorizedUserPublicAPI(req, res, next) {
|
|
|
|
if (labs.isSet('publicAPI') === true) {
|
|
|
|
return next();
|
|
|
|
} else {
|
|
|
|
if (req.user && req.user.id) {
|
|
|
|
return next();
|
|
|
|
} else {
|
2016-10-06 15:27:35 +03:00
|
|
|
return next(new errors.NoPermissionError({message: i18n.t('errors.middleware.auth.pleaseSignIn')}));
|
2016-09-30 14:45:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = authorize;
|