now you can leave teams

This commit is contained in:
Jacob Levine 2019-03-07 20:13:32 -06:00
parent c5dc49f442
commit 77231d00cc
2 changed files with 90 additions and 61 deletions

View File

@ -25,7 +25,7 @@ var uiConfig = {
// function. // function.
// Terms of service url/callback. // Terms of service url/callback.
tosUrl: function() { tosUrl: function() {
alert("this is a test app. don't use it"); alert("this is a test app. don't use it. If you are a 2022 captian, you agree to name Jacob Levine as your successor.");
}, },
// Privacy policy url/callback. // Privacy policy url/callback.
privacyPolicyUrl: function() { privacyPolicyUrl: function() {

View File

@ -61,13 +61,15 @@ window.onload = function() {
} }
}) })
}); });
firebase.firestore.settings({timestampsInSnapshots: true}) firebase.firestore.settings({
timestampsInSnapshots: true
})
} }
function cnt(tn) { function cnt(tn) {
user=firebase.auth().currentUser; user = firebase.auth().currentUser;
push={} push = {}
push[tn]='captian' push[tn] = 'captian'
firebase.firestore().collection("UserAssociations").doc(user.uid).set(push, { firebase.firestore().collection("UserAssociations").doc(user.uid).set(push, {
merge: true merge: true
}).then(function() { }).then(function() {
@ -78,7 +80,7 @@ function cnt(tn) {
teamNums = Object.keys(list) teamNums = Object.keys(list)
document.getElementById('teammem').innerHTML = "" document.getElementById('teammem').innerHTML = ""
for (var i = 0; i < teamNums.length; i++) { for (var i = 0; i < teamNums.length; i++) {
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td></tr>" document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td>" + "<td><input type='button' class='btn' value='leave' onclick='leaveTeam(" + teamNums[i] + ")'></td></tr>"
} }
} else { } else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>" document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
@ -86,67 +88,94 @@ function cnt(tn) {
}) })
}) })
} }
function checkKeyMatch(dt,tn,key){
for(i=0; i<Object.keys(dt).length; i++){ function checkKeyMatch(dt, tn, key) {
if (Object.keys(dt)[i]=="code-"+key){ for (i = 0; i < Object.keys(dt).length; i++) {
if (dt[Object.keys(dt)[i]]=="team-"+tn){ if (Object.keys(dt)[i] == "code-" + key) {
return true if (dt[Object.keys(dt)[i]] == "team-" + tn) {
} return true
} }
} }
return false }
return false
} }
function reqjt(tn,tc){
user=firebase.auth().currentUser; function reqjt(tn, tc) {
firebase.firestore().collection('teamData').doc('joinCodes').get().then(function(doc){ user = firebase.auth().currentUser;
firebase.firestore().collection('teamData').doc('joinCodes').get().then(function(doc) {
if (doc.exists) { if (doc.exists) {
dict=doc.data(); dict = doc.data();
if (checkKeyMatch(dict,tn,tc)){ if (checkKeyMatch(dict, tn, tc)) {
push={}; push = {};
push[tn]='scout'; push[tn] = 'scout';
firebase.firestore().collection("UserAssociations").doc(user.uid).set(push, { firebase.firestore().collection("UserAssociations").doc(user.uid).set(push, {
merge: true merge: true
}).then(function() { }).then(function() {
teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid) teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid)
teamAssoc.get().then(function(doc) { teamAssoc.get().then(function(doc) {
if (doc.exists) { if (doc.exists) {
list = doc.data() list = doc.data()
teamNums = Object.keys(list) teamNums = Object.keys(list)
document.getElementById('teammem').innerHTML = "" document.getElementById('teammem').innerHTML = ""
for (var i = 0; i < teamNums.length; i++) { for (var i = 0; i < teamNums.length; i++) {
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td></tr>" document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td>" + "<td><input type='button' class='btn' value='leave' onclick='leaveTeam(" + teamNums[i] + ")'></td></tr>"
} }
} else { } else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>" document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
} }
}) })
}) })
}else{ } else {
alert("You don't have a correct join key. Please check it and try again.") alert("You don't have a correct join key. Please check it and try again.")
console.log(dict) console.log(dict)
} }
} else { } else {
// doc.data() will be undefined in this case // doc.data() will be undefined in this case
console.log("No such document!"); console.log("No such document!");
} }
}); });
} }
function signout() { function leaveTeam(tn) {
var user = firebase.auth().currentUser; teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid)
firebase.auth().signOut().then( teamAssoc.get().then(function(doc) {
window.location.href = '../'); if (doc.exists) {
} list = doc.data()
delete list[tn]
function deleteAccount() { firebase.firestore().collection("UserAssociations").doc(user.uid).set(list).then(function() {
try { teamAssoc = firebase.firestore().collection('UserAssociations').doc(user.uid)
firebase.auth().currentUser.delete().then( teamAssoc.get().then(function(doc) {
window.location.href = '../'); if (doc.exists) {
} catch (error) { list = doc.data()
if (error.code == 'auth/requires-recent-login') { teamNums = Object.keys(list)
alert("Please sign in again to delete your account.") document.getElementById('teammem').innerHTML = ""
window.location.href = '../'; for (var i = 0; i < teamNums.length; i++) {
document.getElementById('teammem').innerHTML += "<tr><td>" + teamNums[i] + "</td><td>" + list[teamNums[i]] + "</td>" + "<td><input type='button' class='btn' value='leave' onclick='leaveTeam(" + teamNums[i] + ")'></td></tr>"
}
} else {
document.getElementById('teammem').innerHTML = "<tr><td>You are not part of any teams</td></tr>"
}
})
})
)
}
}
function signout() {
var user = firebase.auth().currentUser;
firebase.auth().signOut().then(
window.location.href = '../');
}
function deleteAccount() {
try {
firebase.auth().currentUser.delete().then(
window.location.href = '../');
} catch (error) {
if (error.code == 'auth/requires-recent-login') {
alert("Please sign in again to delete your account.")
window.location.href = '../';
}
} }
} }
}