Add transfer error for too many password attempts

This commit is contained in:
seotts 2021-09-07 12:24:02 -04:00
parent 32466b4efe
commit 5d8d2a05c8
3 changed files with 17 additions and 2 deletions

View file

@ -101,6 +101,7 @@
"studio.transfer.forgotPassword": "Forgot password?", "studio.transfer.forgotPassword": "Forgot password?",
"studio.transfer.alert.somethingWentWrong": "Something went wrong transferring this studio to a new host.", "studio.transfer.alert.somethingWentWrong": "Something went wrong transferring this studio to a new host.",
"studio.transfer.alert.wasntTheRightPassword": "Hmm, that wasnt the right password.", "studio.transfer.alert.wasntTheRightPassword": "Hmm, that wasnt the right password.",
"studio.transfer.alert.tooManyPasswordAttempts": "Too many password attempts. Please try again later.",
"studio.transfer.alert.thisUserCannotBecomeHost": "This user cannot become the host — try transfering to another manager", "studio.transfer.alert.thisUserCannotBecomeHost": "This user cannot become the host — try transfering to another manager",
"studio.remove": "Remove", "studio.remove": "Remove",

View file

@ -11,6 +11,7 @@ const Errors = keyMirror({
SERVER: null, SERVER: null,
PERMISSION: null, PERMISSION: null,
PASSWORD: null, PASSWORD: null,
PASSWORD_ATTEMPT_LIMIT: null,
DUPLICATE: null, DUPLICATE: null,
USER_MUTED: null, USER_MUTED: null,
UNKNOWN_USERNAME: null, UNKNOWN_USERNAME: null,
@ -34,6 +35,9 @@ const normalizeError = (err, body, res) => {
if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION;
if (res.statusCode === 404) return Errors.UNKNOWN_USERNAME; if (res.statusCode === 404) return Errors.UNKNOWN_USERNAME;
if (res.statusCode === 409) return Errors.CANNOT_BE_HOST; if (res.statusCode === 409) return Errors.CANNOT_BE_HOST;
if (res.statusCode === 429 && body.message === 'try again later') {
return Errors.PASSWORD_ATTEMPT_LIMIT;
}
if (res.statusCode === 429) return Errors.RATE_LIMIT; if (res.statusCode === 429) return Errors.RATE_LIMIT;
if (res.statusCode !== 200) return Errors.SERVER; if (res.statusCode !== 200) return Errors.SERVER;
if (body && body.status === 'error') { if (body && body.status === 'error') {

View file

@ -51,6 +51,14 @@ const TransferHostConfirmation = ({
} }
}; };
const validationErrorToMessageId = error => {
switch (error) {
case Errors.PASSWORD: return 'studio.transfer.alert.wasntTheRightPassword';
case Errors.PASSWORD_ATTEMPT_LIMIT: return 'studio.transfer.alert.tooManyPasswordAttempts';
default: return 'studio.transfer.alert.wasntTheRightPassword';
}
};
const handleSubmit = () => { const handleSubmit = () => {
setSubmitting(true); setSubmitting(true);
handleTransferHost(passwordInputValue, hostInfo.newHostUsername, selectedId) handleTransferHost(passwordInputValue, hostInfo.newHostUsername, selectedId)
@ -64,7 +72,7 @@ const TransferHostConfirmation = ({
}) })
.catch(e => { .catch(e => {
// For password errors, show validation alert without closing the modal // For password errors, show validation alert without closing the modal
if (e === Errors.PASSWORD) { if (e === Errors.PASSWORD || e === Errors.PASSWORD_ATTEMPT_LIMIT) {
setSubmitting(false); setSubmitting(false);
setValidationError(e); setValidationError(e);
return; return;
@ -137,7 +145,9 @@ const TransferHostConfirmation = ({
/> />
{validationError && <ValidationMessage {validationError && <ValidationMessage
className="transfer-password-validation" className="transfer-password-validation"
message={intl.formatMessage({id: 'studio.transfer.alert.wasntTheRightPassword'})} message={intl.formatMessage({
id: validationErrorToMessageId(validationError)
})}
mode="error" mode="error"
/>} />}
</div> </div>