1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-10 23:53:31 -05:00

Add scope middleware to invites

This commit is contained in:
Jack Foltz 2018-01-15 11:48:58 -05:00
parent 6c89cdd29e
commit 4b4d32ec9c
Signed by: foltik
GPG Key ID: 303F88F996E95541

View File

@ -3,6 +3,18 @@ var router = express.Router();
var Invite = require('../models/Invite.js'); var Invite = require('../models/Invite.js');
var requireScope = function (perm) {
return function(req, res, next) {
User.findOne({username: req.session.passport.user}, function(err, user) {
if (err) throw err;
if (user.scope.indexOf(perm) === -1)
res.status(400).json({'message': 'No permission.'});
else
next();
});
}
};
router.post('/create', function (req, res) { router.post('/create', function (req, res) {
if (!req.body.scope) { if (!req.body.scope) {
res.status(400).json({'message': 'Bad request.'}); res.status(400).json({'message': 'Bad request.'});