mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 17:16:11 -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
|
||||
return validate.validateEmailRemotely(email).then(
|
||||
remoteResult => {
|
||||
this.emailRemoteCache[email] = remoteResult;
|
||||
// cache result, if it successfully heard back from server
|
||||
if (remoteResult.requestSucceeded) {
|
||||
this.emailRemoteCache[email] = remoteResult;
|
||||
}
|
||||
return remoteResult;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -56,7 +56,10 @@ class UsernameStep extends React.Component {
|
|||
// username is not in our cache
|
||||
return validate.validateUsernameRemotely(username).then(
|
||||
remoteResult => {
|
||||
this.usernameRemoteCache[username] = remoteResult;
|
||||
// cache result, if it successfully heard back from server
|
||||
if (remoteResult.requestSucceeded) {
|
||||
this.usernameRemoteCache[username] = remoteResult;
|
||||
}
|
||||
return remoteResult;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -21,21 +21,21 @@ module.exports.validateUsernameRemotely = username => (
|
|||
uri: `/accounts/checkusername/${username}/`
|
||||
}, (err, body, res) => {
|
||||
if (err || res.statusCode !== 200) {
|
||||
resolve({valid: false, errMsgId: 'general.error'});
|
||||
resolve({requestSucceeded: false, valid: false, errMsgId: 'general.error'});
|
||||
}
|
||||
switch (body.msg) {
|
||||
case 'valid username':
|
||||
resolve({valid: true});
|
||||
resolve({requestSucceeded: true, valid: true});
|
||||
break;
|
||||
case 'username exists':
|
||||
resolve({valid: false, errMsgId: 'registration.validationUsernameExists'});
|
||||
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationUsernameExists'});
|
||||
break;
|
||||
case 'bad username': // i.e., vulgar
|
||||
resolve({valid: false, errMsgId: 'registration.validationUsernameNotAllowed'});
|
||||
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationUsernameNotAllowed'});
|
||||
break;
|
||||
case 'invalid username':
|
||||
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) => {
|
||||
if (!password) {
|
||||
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'};
|
||||
} else if (password === 'password') {
|
||||
return {valid: false, errMsgId: 'registration.validationPasswordNotEquals'};
|
||||
|
@ -86,16 +88,16 @@ module.exports.validateEmailRemotely = email => (
|
|||
uri: '/accounts/check_email/'
|
||||
}, (err, body, res) => {
|
||||
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) {
|
||||
case 'valid email':
|
||||
resolve({valid: true});
|
||||
resolve({requestSucceeded: true, valid: true});
|
||||
break;
|
||||
case 'Scratch is not allowed to send email to this address.': // e.g., bad TLD or block-listed
|
||||
case 'Enter a valid email address.':
|
||||
default:
|
||||
resolve({valid: false, errMsgId: 'registration.validationEmailInvalid'});
|
||||
resolve({requestSucceeded: true, valid: false, errMsgId: 'registration.validationEmailInvalid'});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue