mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
77b7b03ead
GitOrigin-RevId: 2fffcce053d5bf452508774b555959610db9a2c7
30 lines
764 B
JavaScript
30 lines
764 B
JavaScript
const RateLimiter = require('../../infrastructure/RateLimiter')
|
|
const { promisifyAll } = require('../../util/promises')
|
|
|
|
const ONE_MIN = 60
|
|
const ATTEMPT_LIMIT = 10
|
|
|
|
function processLoginRequest(email, callback) {
|
|
const opts = {
|
|
endpointName: 'login',
|
|
throttle: ATTEMPT_LIMIT,
|
|
timeInterval: ONE_MIN * 2,
|
|
subjectName: email
|
|
}
|
|
RateLimiter.addCount(opts, (err, shouldAllow) => callback(err, shouldAllow))
|
|
}
|
|
|
|
function recordSuccessfulLogin(email, callback) {
|
|
if (callback == null) {
|
|
callback = function() {}
|
|
}
|
|
RateLimiter.clearRateLimit('login', email, callback)
|
|
}
|
|
|
|
const LoginRateLimiter = {
|
|
processLoginRequest,
|
|
recordSuccessfulLogin
|
|
}
|
|
LoginRateLimiter.promises = promisifyAll(LoginRateLimiter)
|
|
|
|
module.exports = LoginRateLimiter
|