Imported MEAN stack files
This commit is contained in:
33
config/middlewares/authorization.js
Executable file
33
config/middlewares/authorization.js
Executable file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Generic require login routing middleware
|
||||
*/
|
||||
exports.requiresLogin = function(req, res, next) {
|
||||
if (!req.isAuthenticated()) {
|
||||
return res.send(401, 'User is not authorized');
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
/**
|
||||
* User authorizations routing middleware
|
||||
*/
|
||||
exports.user = {
|
||||
hasAuthorization: function(req, res, next) {
|
||||
if (req.profile.id != req.user.id) {
|
||||
return res.send(401, 'User is not authorized');
|
||||
}
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Article authorizations routing middleware
|
||||
*/
|
||||
exports.article = {
|
||||
hasAuthorization: function(req, res, next) {
|
||||
if (req.article.user.id != req.user.id) {
|
||||
return res.send(401, 'User is not authorized');
|
||||
}
|
||||
next();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user