diff --git a/functions/index.js b/functions/index.js index cc2555a5f..f523f2b23 100644 --- a/functions/index.js +++ b/functions/index.js @@ -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; } }) diff --git a/public/js/account.js b/public/js/account.js index afbe8c497..7568ca281 100644 --- a/public/js/account.js +++ b/public/js/account.js @@ -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);