added a more descriptive error to the sign up form

This commit is contained in:
Jack 2020-06-21 23:00:33 +01:00
parent ee50cf96bf
commit e4b468cc25
2 changed files with 12 additions and 4 deletions

View file

@ -62,13 +62,17 @@ function isUsernameValid(name){
}
exports.checkNameAvailability = functions.https.onCall((request,response) => {
// 1 - available
// -1 - unavailable (taken)
// -2 - not valid name
// -999 - unknown error
try{
if(!isUsernameValid(request.name)) return 0;
if(!isUsernameValid(request.name)) return -2;
return getAllNames().then(data => {
let available = 1;
data.forEach(name =>{
try{
if(name.toLowerCase() === request.name.toLowerCase()) available = 0;
if(name.toLowerCase() === request.name.toLowerCase()) available = -1;
}catch(e){
//
}
@ -76,7 +80,7 @@ exports.checkNameAvailability = functions.https.onCall((request,response) => {
return available;
});
}catch(e){
return -1;
return -999;
}
})

View file

@ -88,10 +88,14 @@ function signUp() {
const namecheck = firebase.functions().httpsCallable('checkNameAvailability')
namecheck({name:nname}).then(d => {
if(d.data === 0){
if(d.data === -1){
showNotification("Name unavailable", 3000);
$(".pageLogin .preloader").addClass('hidden');
return;
}else if(d.data === -2){
showNotification("Name cannot contain special characters or contain more than 12 characters. Can include _ . and -", 8000);
$(".pageLogin .preloader").addClass('hidden');
return;
}else if(d.data === 1){
if (password != passwordVerify) {
showNotification("Passwords do not match", 3000);