mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 15:47:53 -05:00
Add transfer error for too many password attempts
This commit is contained in:
parent
32466b4efe
commit
5d8d2a05c8
3 changed files with 17 additions and 2 deletions
|
@ -101,6 +101,7 @@
|
|||
"studio.transfer.forgotPassword": "Forgot password?",
|
||||
"studio.transfer.alert.somethingWentWrong": "Something went wrong transferring this studio to a new host.",
|
||||
"studio.transfer.alert.wasntTheRightPassword": "Hmm, that wasn’t 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.remove": "Remove",
|
||||
|
|
|
@ -11,6 +11,7 @@ const Errors = keyMirror({
|
|||
SERVER: null,
|
||||
PERMISSION: null,
|
||||
PASSWORD: null,
|
||||
PASSWORD_ATTEMPT_LIMIT: null,
|
||||
DUPLICATE: null,
|
||||
USER_MUTED: 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 === 404) return Errors.UNKNOWN_USERNAME;
|
||||
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 !== 200) return Errors.SERVER;
|
||||
if (body && body.status === 'error') {
|
||||
|
|
|
@ -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 = () => {
|
||||
setSubmitting(true);
|
||||
handleTransferHost(passwordInputValue, hostInfo.newHostUsername, selectedId)
|
||||
|
@ -64,7 +72,7 @@ const TransferHostConfirmation = ({
|
|||
})
|
||||
.catch(e => {
|
||||
// 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);
|
||||
setValidationError(e);
|
||||
return;
|
||||
|
@ -137,7 +145,9 @@ const TransferHostConfirmation = ({
|
|||
/>
|
||||
{validationError && <ValidationMessage
|
||||
className="transfer-password-validation"
|
||||
message={intl.formatMessage({id: 'studio.transfer.alert.wasntTheRightPassword'})}
|
||||
message={intl.formatMessage({
|
||||
id: validationErrorToMessageId(validationError)
|
||||
})}
|
||||
mode="error"
|
||||
/>}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue