mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 02:56:20 -05:00
username step and email step caches ignore api failures
This commit is contained in:
parent
9221b6f6b5
commit
49fe86ae3c
3 changed files with 19 additions and 11 deletions
|
@ -91,7 +91,10 @@ class EmailStep extends React.Component {
|
||||||
// email is not in our cache
|
// email is not in our cache
|
||||||
return validate.validateEmailRemotely(email).then(
|
return validate.validateEmailRemotely(email).then(
|
||||||
remoteResult => {
|
remoteResult => {
|
||||||
this.emailRemoteCache[email] = remoteResult;
|
// cache result, if it successfully heard back from server
|
||||||
|
if (remoteResult.requestSucceeded) {
|
||||||
|
this.emailRemoteCache[email] = remoteResult;
|
||||||
|
}
|
||||||
return remoteResult;
|
return remoteResult;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -56,7 +56,10 @@ class UsernameStep extends React.Component {
|
||||||
// username is not in our cache
|
// username is not in our cache
|
||||||
return validate.validateUsernameRemotely(username).then(
|
return validate.validateUsernameRemotely(username).then(
|
||||||
remoteResult => {
|
remoteResult => {
|
||||||
this.usernameRemoteCache[username] = remoteResult;
|
// cache result, if it successfully heard back from server
|
||||||
|
if (remoteResult.requestSucceeded) {
|
||||||
|
this.usernameRemoteCache[username] = remoteResult;
|
||||||
|
}
|
||||||
return remoteResult;
|
return remoteResult;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,21 +21,21 @@ module.exports.validateUsernameRemotely = username => (
|
||||||
uri: `/accounts/checkusername/${username}/`
|
uri: `/accounts/checkusername/${username}/`
|
||||||
}, (err, body, res) => {
|
}, (err, body, res) => {
|
||||||
if (err || res.statusCode !== 200) {
|
if (err || res.statusCode !== 200) {
|
||||||
resolve({valid: false, errMsgId: 'general.error'});
|
resolve({requestSucceeded: false, valid: false, errMsgId: 'general.error'});
|
||||||
}
|
}
|
||||||
switch (body.msg) {
|
switch (body.msg) {
|
||||||
case 'valid username':
|
case 'valid username':
|
||||||
resolve({valid: true});
|
resolve({requestSucceeded: true, valid: true});
|
||||||
break;
|
break;
|
||||||
case 'username exists':
|
case 'username exists':
|
||||||
resolve({valid: false, errMsgId: 'registration.validationUsernameExists'});
|
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationUsernameExists'});
|
||||||
break;
|
break;
|
||||||
case 'bad username': // i.e., vulgar
|
case 'bad username': // i.e., vulgar
|
||||||
resolve({valid: false, errMsgId: 'registration.validationUsernameNotAllowed'});
|
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationUsernameNotAllowed'});
|
||||||
break;
|
break;
|
||||||
case 'invalid username':
|
case 'invalid username':
|
||||||
default:
|
default:
|
||||||
resolve({valid: false, errMsgId: 'registration.validationUsernameNotAllowed'});
|
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationUsernameNotAllowed'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -50,7 +50,9 @@ module.exports.validateUsernameRemotely = username => (
|
||||||
module.exports.validatePassword = (password, username) => {
|
module.exports.validatePassword = (password, username) => {
|
||||||
if (!password) {
|
if (!password) {
|
||||||
return {valid: false, errMsgId: 'general.required'};
|
return {valid: false, errMsgId: 'general.required'};
|
||||||
} else if (password.length < 6) {
|
// get length of password, considering unicode symbols as single chars.
|
||||||
|
// see discussion at https://stackoverflow.com/a/54370584/2308190
|
||||||
|
} else if (Array.from(password).length < 6) {
|
||||||
return {valid: false, errMsgId: 'registration.validationPasswordLength'};
|
return {valid: false, errMsgId: 'registration.validationPasswordLength'};
|
||||||
} else if (password === 'password') {
|
} else if (password === 'password') {
|
||||||
return {valid: false, errMsgId: 'registration.validationPasswordNotEquals'};
|
return {valid: false, errMsgId: 'registration.validationPasswordNotEquals'};
|
||||||
|
@ -86,16 +88,16 @@ module.exports.validateEmailRemotely = email => (
|
||||||
uri: '/accounts/check_email/'
|
uri: '/accounts/check_email/'
|
||||||
}, (err, body, res) => {
|
}, (err, body, res) => {
|
||||||
if (err || res.statusCode !== 200 || !body || body.length < 1 || !body[0].msg) {
|
if (err || res.statusCode !== 200 || !body || body.length < 1 || !body[0].msg) {
|
||||||
resolve({valid: false, errMsgId: 'general.apiError'});
|
resolve({requestSucceeded: false, valid: false, errMsgId: 'general.apiError'});
|
||||||
}
|
}
|
||||||
switch (body[0].msg) {
|
switch (body[0].msg) {
|
||||||
case 'valid email':
|
case 'valid email':
|
||||||
resolve({valid: true});
|
resolve({requestSucceeded: true, valid: true});
|
||||||
break;
|
break;
|
||||||
case 'Scratch is not allowed to send email to this address.': // e.g., bad TLD or block-listed
|
case 'Scratch is not allowed to send email to this address.': // e.g., bad TLD or block-listed
|
||||||
case 'Enter a valid email address.':
|
case 'Enter a valid email address.':
|
||||||
default:
|
default:
|
||||||
resolve({valid: false, errMsgId: 'registration.validationEmailInvalid'});
|
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationEmailInvalid'});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue