mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-20 06:29:53 +01:00
webaccess: Use arrow functions instead of function
keyword
This commit is contained in:
parent
726101d6a8
commit
a7be5278a3
1 changed files with 15 additions and 15 deletions
|
@ -9,14 +9,14 @@ var sessionModule = require('express-session');
|
||||||
var cookieParser = require('cookie-parser');
|
var cookieParser = require('cookie-parser');
|
||||||
|
|
||||||
// checks for basic http auth
|
// checks for basic http auth
|
||||||
exports.basicAuth = function(req, res, next) {
|
exports.basicAuth = (req, res, next) => {
|
||||||
var hookResultMangle = function(cb) {
|
var hookResultMangle = (cb) => {
|
||||||
return function(err, data) {
|
return (err, data) => {
|
||||||
return cb(!err && data.length && data[0]);
|
return cb(!err && data.length && data[0]);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var authorize = function(cb) {
|
var authorize = (cb) => {
|
||||||
// Do not require auth for static paths and the API...this could be a bit brittle
|
// Do not require auth for static paths and the API...this could be a bit brittle
|
||||||
if (req.path.match(/^\/(static|javascripts|pluginfw|api)/)) return cb(true);
|
if (req.path.match(/^\/(static|javascripts|pluginfw|api)/)) return cb(true);
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@ exports.basicAuth = function(req, res, next) {
|
||||||
hooks.aCallFirst('authorize', {req: req, res: res, next: next, resource: req.path}, hookResultMangle(cb));
|
hooks.aCallFirst('authorize', {req: req, res: res, next: next, resource: req.path}, hookResultMangle(cb));
|
||||||
};
|
};
|
||||||
|
|
||||||
var authenticate = function(cb) {
|
var authenticate = (cb) => {
|
||||||
// If auth headers are present use them to authenticate...
|
// If auth headers are present use them to authenticate...
|
||||||
if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
|
if (req.headers.authorization && req.headers.authorization.search('Basic ') === 0) {
|
||||||
var userpass = Buffer.from(req.headers.authorization.split(' ')[1], 'base64').toString().split(':');
|
var userpass = Buffer.from(req.headers.authorization.split(' ')[1], 'base64').toString().split(':');
|
||||||
var username = userpass.shift();
|
var username = userpass.shift();
|
||||||
var password = userpass.join(':');
|
var password = userpass.join(':');
|
||||||
var fallback = function(success) {
|
var fallback = (success) => {
|
||||||
if (success) return cb(true);
|
if (success) return cb(true);
|
||||||
if (!(username in settings.users)) {
|
if (!(username in settings.users)) {
|
||||||
httpLogger.info(`Failed authentication from IP ${req.ip} - no such user`);
|
httpLogger.info(`Failed authentication from IP ${req.ip} - no such user`);
|
||||||
|
@ -58,15 +58,15 @@ exports.basicAuth = function(req, res, next) {
|
||||||
|
|
||||||
|
|
||||||
/* Authentication OR authorization failed. */
|
/* Authentication OR authorization failed. */
|
||||||
var failure = function() {
|
var failure = () => {
|
||||||
return hooks.aCallFirst('authFailure', {req: req, res: res, next: next}, hookResultMangle(function(ok) {
|
return hooks.aCallFirst('authFailure', {req: req, res: res, next: next}, hookResultMangle((ok) => {
|
||||||
if (ok) return;
|
if (ok) return;
|
||||||
/* No plugin handler for invalid auth. Return Auth required
|
/* No plugin handler for invalid auth. Return Auth required
|
||||||
* Headers, delayed for 1 second, if authentication failed
|
* Headers, delayed for 1 second, if authentication failed
|
||||||
* before. */
|
* before. */
|
||||||
res.header('WWW-Authenticate', 'Basic realm="Protected Area"');
|
res.header('WWW-Authenticate', 'Basic realm="Protected Area"');
|
||||||
if (req.headers.authorization) {
|
if (req.headers.authorization) {
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
res.status(401).send('Authentication required');
|
res.status(401).send('Authentication required');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
} else {
|
} else {
|
||||||
|
@ -87,11 +87,11 @@ exports.basicAuth = function(req, res, next) {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
authorize(function(ok) {
|
authorize((ok) => {
|
||||||
if (ok) return next();
|
if (ok) return next();
|
||||||
authenticate(function(ok) {
|
authenticate((ok) => {
|
||||||
if (!ok) return failure();
|
if (!ok) return failure();
|
||||||
authorize(function(ok) {
|
authorize((ok) => {
|
||||||
if (ok) return next();
|
if (ok) return next();
|
||||||
failure();
|
failure();
|
||||||
});
|
});
|
||||||
|
@ -101,12 +101,12 @@ exports.basicAuth = function(req, res, next) {
|
||||||
|
|
||||||
exports.secret = null;
|
exports.secret = null;
|
||||||
|
|
||||||
exports.expressConfigure = function(hook_name, args, cb) {
|
exports.expressConfigure = (hook_name, args, cb) => {
|
||||||
// Measure response time
|
// Measure response time
|
||||||
args.app.use(function(req, res, next) {
|
args.app.use((req, res, next) => {
|
||||||
var stopWatch = stats.timer('httpRequests').start();
|
var stopWatch = stats.timer('httpRequests').start();
|
||||||
var sendFn = res.send;
|
var sendFn = res.send;
|
||||||
res.send = function() {
|
res.send = function() { // function, not arrow, due to use of 'arguments'
|
||||||
stopWatch.end();
|
stopWatch.end();
|
||||||
sendFn.apply(res, arguments);
|
sendFn.apply(res, arguments);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue