remove code duplication

This commit is contained in:
booo 2012-02-08 15:52:13 +01:00
parent 736aaa2800
commit e6e81135a7
4 changed files with 33 additions and 59 deletions

View file

@ -1,6 +1,8 @@
var ERR = require('async-stacktrace');
module.exports = function(app)
{
//redirects browser to the pad's sanitized url if needed. otherwise, renders the html
//redirects browser to the pad's sanitized url if needed. otherwise, renders the html
app.param('pad', function (req, res, next, padId) {
//ensure the padname is valid and the url doesn't end with a /
if(!app.padManager.isValidPadId(padId) || /\/$/.test(req.url))
@ -26,3 +28,30 @@ module.exports = function(app)
}
});
};
module.exports.hasPadAccess = function(app)
{
//checks for padAccess
var hasPadAccess = function hasPadAccess(req, res, callback)
{
app.securityManager.checkAccess(req.params.pad, req.cookies.sessionid, req.cookies.token, req.cookies.password, function(err, accessObj)
{
if(ERR(err, callback)) return;
//there is access, continue
if(accessObj.accessStatus == "grant")
{
callback();
}
//no access
else
{
res.send("403 - Can't touch this", 403);
}
});
};
return hasPadAccess;
};