mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
remove code duplication
This commit is contained in:
parent
736aaa2800
commit
e6e81135a7
4 changed files with 33 additions and 59 deletions
|
@ -2,26 +2,7 @@ var ERR = require("async-stacktrace");
|
||||||
|
|
||||||
module.exports = function(app)
|
module.exports = function(app)
|
||||||
{
|
{
|
||||||
//TODO put this into module
|
var hasPadAccess = require('./preconditions').hasPadAccess(app);
|
||||||
//checks for padAccess
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//serve timeslider.html under /p/$padname/timeslider
|
//serve timeslider.html under /p/$padname/timeslider
|
||||||
app.get('/p/:pad/:rev?/export/:type', function(req, res, next)
|
app.get('/p/:pad/:rev?/export/:type', function(req, res, next)
|
||||||
|
|
|
@ -2,26 +2,8 @@ var ERR = require("async-stacktrace");
|
||||||
|
|
||||||
module.exports = function(app)
|
module.exports = function(app)
|
||||||
{
|
{
|
||||||
//TODO put this into module
|
|
||||||
//checks for padAccess
|
|
||||||
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
|
var hasPadAccess = require('./preconditions').hasPadAccess(app);
|
||||||
if(accessObj.accessStatus == "grant")
|
|
||||||
{
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
//no access
|
|
||||||
else
|
|
||||||
{
|
|
||||||
res.send("403 - Can't touch this", 403);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//handle import requests
|
//handle import requests
|
||||||
app.post('/p/:pad/import', function(req, res, next)
|
app.post('/p/:pad/import', function(req, res, next)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
var ERR = require('async-stacktrace');
|
||||||
|
|
||||||
module.exports = function(app)
|
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) {
|
app.param('pad', function (req, res, next, padId) {
|
||||||
//ensure the padname is valid and the url doesn't end with a /
|
//ensure the padname is valid and the url doesn't end with a /
|
||||||
if(!app.padManager.isValidPadId(padId) || /\/$/.test(req.url))
|
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;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
|
@ -3,26 +3,8 @@ var ERR = require('async-stacktrace');
|
||||||
|
|
||||||
module.exports = function(app)
|
module.exports = function(app)
|
||||||
{
|
{
|
||||||
//TODO put this into module
|
|
||||||
//checks for padAccess
|
|
||||||
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
|
var hasPadAccess = require('./preconditions').hasPadAccess(app);
|
||||||
if(accessObj.accessStatus == "grant")
|
|
||||||
{
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
//no access
|
|
||||||
else
|
|
||||||
{
|
|
||||||
res.send("403 - Can't touch this", 403);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//serve read only pad
|
//serve read only pad
|
||||||
app.get('/ro/:id', function(req, res)
|
app.get('/ro/:id', function(req, res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue