|
|
@@ -56,29 +56,31 @@ function rateLimit(rateLimiter, opts = {}) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function loginRateLimitEmail(req, res, next) {
|
|
|
- const { email } = req.body
|
|
|
- if (!email) {
|
|
|
- return next()
|
|
|
- }
|
|
|
- LoginRateLimiter.processLoginRequest(email, (err, isAllowed) => {
|
|
|
- if (err) {
|
|
|
- return next(err)
|
|
|
- }
|
|
|
- if (isAllowed) {
|
|
|
- next()
|
|
|
- } else {
|
|
|
- logger.warn({ email }, 'rate limit exceeded')
|
|
|
- res.status(429) // Too many requests
|
|
|
- res.json({
|
|
|
- message: {
|
|
|
- type: 'error',
|
|
|
- text: req.i18n.translate('to_many_login_requests_2_mins'),
|
|
|
- key: 'to-many-login-requests-2-mins',
|
|
|
- },
|
|
|
- })
|
|
|
+function loginRateLimitEmail(emailField = 'email') {
|
|
|
+ return function (req, res, next) {
|
|
|
+ const email = req.body[emailField]
|
|
|
+ if (!email) {
|
|
|
+ return next()
|
|
|
}
|
|
|
- })
|
|
|
+ LoginRateLimiter.processLoginRequest(email, (err, isAllowed) => {
|
|
|
+ if (err) {
|
|
|
+ return next(err)
|
|
|
+ }
|
|
|
+ if (isAllowed) {
|
|
|
+ next()
|
|
|
+ } else {
|
|
|
+ logger.warn({ email }, 'rate limit exceeded')
|
|
|
+ res.status(429) // Too many requests
|
|
|
+ res.json({
|
|
|
+ message: {
|
|
|
+ type: 'error',
|
|
|
+ text: req.i18n.translate('to_many_login_requests_2_mins'),
|
|
|
+ key: 'to-many-login-requests-2-mins',
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const RateLimiterMiddleware = {
|