2017-01-24 00:44:39 +03:00
|
|
|
var url = require('url'),
|
|
|
|
spamPrevention = require('./api/spam-prevention');
|
2016-11-08 14:33:19 +03:00
|
|
|
|
2017-01-24 00:44:39 +03:00
|
|
|
/**
|
|
|
|
* We set ignoreIP to false, because we tell brute-knex to use `req.ip`.
|
|
|
|
* We can use `req.ip`, because express trust proxy option is enabled.
|
|
|
|
*/
|
2016-11-08 14:33:19 +03:00
|
|
|
module.exports = {
|
2017-01-24 00:44:39 +03:00
|
|
|
/**
|
|
|
|
* block per route per ip
|
|
|
|
*/
|
2017-03-13 23:07:12 +03:00
|
|
|
globalBlock: function (req, res, next) {
|
|
|
|
return spamPrevention.globalBlock().getMiddleware({
|
|
|
|
ignoreIP: false,
|
|
|
|
key: function (req, res, next) {
|
|
|
|
next(url.parse(req.url).pathname);
|
|
|
|
}
|
|
|
|
})(req, res, next);
|
|
|
|
},
|
2017-01-24 00:44:39 +03:00
|
|
|
/**
|
|
|
|
* block per route per ip
|
|
|
|
*/
|
2017-03-13 23:07:12 +03:00
|
|
|
globalReset: function (req, res, next) {
|
|
|
|
return spamPrevention.globalReset().getMiddleware({
|
|
|
|
ignoreIP: false,
|
|
|
|
key: function (req, res, next) {
|
|
|
|
next(url.parse(req.url).pathname);
|
|
|
|
}
|
|
|
|
})(req, res, next);
|
|
|
|
},
|
2017-01-24 00:44:39 +03:00
|
|
|
/**
|
|
|
|
* block per user
|
|
|
|
* username === email!
|
|
|
|
*/
|
2017-03-13 23:07:12 +03:00
|
|
|
userLogin: function (req, res, next) {
|
|
|
|
return spamPrevention.userLogin().getMiddleware({
|
|
|
|
ignoreIP: false,
|
|
|
|
key: function (req, res, next) {
|
|
|
|
if (req.body.username) {
|
|
|
|
return next(req.body.username + 'login');
|
|
|
|
}
|
2016-11-17 16:02:56 +03:00
|
|
|
|
2017-03-13 23:07:12 +03:00
|
|
|
if (req.body.authorizationCode) {
|
|
|
|
return next(req.body.authorizationCode + 'login');
|
|
|
|
}
|
2016-11-17 16:02:56 +03:00
|
|
|
|
2017-03-13 23:07:12 +03:00
|
|
|
if (req.body.refresh_token) {
|
|
|
|
return next(req.body.refresh_token + 'login');
|
|
|
|
}
|
2016-11-17 16:02:56 +03:00
|
|
|
|
2017-03-13 23:07:12 +03:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
})(req, res, next);
|
|
|
|
},
|
2017-01-24 00:44:39 +03:00
|
|
|
/**
|
|
|
|
* block per user
|
|
|
|
*/
|
2017-03-13 23:07:12 +03:00
|
|
|
userReset: function (req, res, next) {
|
|
|
|
return spamPrevention.userReset().getMiddleware({
|
|
|
|
ignoreIP: false,
|
|
|
|
key: function (req, res, next) {
|
|
|
|
next(req.body.username + 'reset');
|
|
|
|
}
|
|
|
|
})(req, res, next);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* block per ip
|
|
|
|
*/
|
|
|
|
privateBlog: function (req, res, next) {
|
|
|
|
return spamPrevention.privateBlog().getMiddleware({
|
|
|
|
ignoreIP: false,
|
|
|
|
key: function (req, res, next) {
|
|
|
|
next('privateblog');
|
|
|
|
}
|
|
|
|
})(req, res, next);
|
|
|
|
}
|
2016-11-08 14:33:19 +03:00
|
|
|
};
|