mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-26 18:51:50 +02:00
* Promisify `AuthenticationController.doPassportLogin` * Update tests `AuthenticationController.doPassportLogin` * Add test on error handling for `AuthenticationController.doPassportLogin` * Add test on error handling for `V1LoginController.doLogin` * Extract error handling to `getErrorObject` function * Simplify code * Add `Metrics` calls * Add `password is too long` in AuthenticationController * Make `info` object consistent with the rest of the codebase * Move error handling to `AuthenticationManager.handleAuthenticateErrors` * Move `handleAuthenticateErrors` to other file I moved this solely because I didn't manage to test it otherwise * Update tests * Remove `preDoPassportLogin` hook call * Remove test on `preDoPassportLogin` * Use try/catch block instead of `.catch()` * Revert "Use try/catch block instead of `.catch()`" This reverts commit 3475afa93ce4af7ad55c91bfc1d7ad3317600ea5. * Replace `.catch` by `try/catch` GitOrigin-RevId: 3fba65c30a2c5fc6e5abcd5b83c52801852ed462
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
const Metrics = require('@overleaf/metrics')
|
|
const OError = require('@overleaf/o-error')
|
|
const Settings = require('@overleaf/settings')
|
|
const Errors = require('../Errors/Errors')
|
|
|
|
class InvalidEmailError extends Errors.BackwardCompatibleError {}
|
|
class InvalidPasswordError extends Errors.BackwardCompatibleError {}
|
|
class ParallelLoginError extends Errors.BackwardCompatibleError {}
|
|
class PasswordMustBeDifferentError extends Errors.BackwardCompatibleError {}
|
|
class PasswordReusedError extends Errors.BackwardCompatibleError {}
|
|
|
|
function handleAuthenticateErrors(error, req) {
|
|
if (error.message === 'password is too long') {
|
|
Metrics.inc('login_failure_reason', 1, {
|
|
status: 'password_is_too_long',
|
|
})
|
|
return {
|
|
status: 422,
|
|
type: 'error',
|
|
key: 'password-too-long',
|
|
text: req.i18n.translate('password_too_long_please_reset'),
|
|
}
|
|
}
|
|
if (error instanceof ParallelLoginError) {
|
|
Metrics.inc('login_failure_reason', 1, { status: 'parallel_login' })
|
|
return { status: 429 }
|
|
}
|
|
if (error instanceof PasswordReusedError) {
|
|
Metrics.inc('login_failure_reason', 1, {
|
|
status: 'password_compromised',
|
|
})
|
|
const text = `${req.i18n
|
|
.translate('password_compromised_try_again_or_use_known_device_or_reset')
|
|
.replace('<0>', '')
|
|
.replace('</0>', ' (https://haveibeenpwned.com/passwords)')
|
|
.replace('<1>', '')
|
|
.replace('</1>', ` (${Settings.siteUrl}/user/password/reset)`)}.`
|
|
return {
|
|
status: 400,
|
|
type: 'error',
|
|
key: 'password-compromised',
|
|
text,
|
|
}
|
|
}
|
|
Metrics.inc('login_failure_reason', 1, {
|
|
status: error instanceof OError ? error.name : 'error',
|
|
})
|
|
throw error
|
|
}
|
|
|
|
module.exports = {
|
|
InvalidEmailError,
|
|
InvalidPasswordError,
|
|
ParallelLoginError,
|
|
PasswordMustBeDifferentError,
|
|
PasswordReusedError,
|
|
handleAuthenticateErrors,
|
|
}
|