tra-analysis/website/public/profile/scripts.js

105 lines
3.9 KiB
JavaScript
Raw Normal View History

2019-02-09 18:14:55 +00:00
/* Set the width of the side navigation to 250px and the left margin of the page content to 250px and add a black background color to body */
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
2019-02-09 21:44:46 +00:00
for (var i = 0; i < document.getElementsByClassName("btn").length; i++) {
document.getElementsByClassName("btn")[i].style.backgroundColor="rgba(0,0,0,.2)"
2019-02-09 21:42:16 +00:00
}
2019-02-09 18:14:55 +00:00
}
/* Set the width of the side navigation to 0 and the left margin of the page content to 0, and the background color of body to white */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
document.body.style.backgroundColor = "white";
2019-02-09 21:44:46 +00:00
for (var i = 0; i < document.getElementsByClassName("btn").length; i++) {
document.getElementsByClassName("btn")[i].style.backgroundColor="buttonface"
2019-02-09 21:42:16 +00:00
}
2019-02-09 18:14:55 +00:00
}
window.onload = function() {
document.getElementById('sideload').style.display = 'block';
var config = {
apiKey: "(insert the TitanScout Api Key Here)",
authDomain: "titanscoutandroid.firebaseapp.com",
databaseURL: "https://titanscoutandroid.firebaseio.com",
projectId: "titanscoutandroid",
storageBucket: "titanscoutandroid.appspot.com",
messagingSenderId: "1097635313476"
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function(user) {
2019-02-09 18:17:47 +00:00
if (user != null) {
if (user.displayName != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.displayName;
2019-02-09 21:25:25 +00:00
document.getElementById('newDN').innerHTML = user.displayName;
2019-02-09 18:17:47 +00:00
} else if (user.email != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.email;
} else if (user.phoneNumber != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.phoneNumber;
2019-02-09 18:14:55 +00:00
} else {
2019-02-09 18:17:47 +00:00
document.getElementById('status').innerHTML = "You are signed in.";
}
2019-02-09 20:30:58 +00:00
if (user.email != null) {
2019-02-09 21:25:25 +00:00
document.getElementById('newEM').innerHTML = user.email;
2019-02-09 20:30:58 +00:00
}
2019-02-09 18:17:47 +00:00
} else {
window.location.replace('../');
}
});
2019-02-09 18:14:55 +00:00
}
2019-02-09 20:30:58 +00:00
function signout() {
var user = firebase.auth().currentUser;
2019-02-13 02:20:30 +00:00
firebase.auth().signOut().then(
window.location.href = '../');
2019-02-09 20:30:58 +00:00
}
function deleteAccount() {
try {
2019-02-13 02:20:30 +00:00
firebase.auth().currentUser.delete().then(
window.location.href = '../');
2019-02-09 20:30:58 +00:00
} catch (error) {
if (error.code == 'auth/requires-recent-login') {
alert("Please sign in again to delete your account.")
window.location.href = '../';
}
}
}
2019-02-13 02:20:30 +00:00
2019-02-09 20:30:58 +00:00
function updun() {
var user = firebase.auth().currentUser;
user.updateProfile({
2019-02-09 21:25:25 +00:00
displayName: document.getElementById('newDN').innerHTML,
2019-02-09 20:30:58 +00:00
}).then(function() {
2019-02-09 21:25:25 +00:00
document.getElementById('newDN').innerHTML = firebase.auth().currentUser.displayName;
2019-02-09 20:30:58 +00:00
document.getElementById('status').innerHTML = "You are signed in as: " + firebase.auth().currentUser.displayName;
firebase.firestore().collection("users").doc(user.uid).set({alias:firebase.auth().currentUser.displayName}, {
2019-03-08 03:16:54 +00:00
merge: true
2019-03-08 03:18:13 +00:00
})
2019-02-09 20:30:58 +00:00
}).catch(function(error) {
alert("there was a problem: " + error)
});
}
function updem() {
var user = firebase.auth().currentUser;
2019-02-09 21:25:25 +00:00
user.updateEmail(document.getElementById('newEM').innerHTML).then(function() {
2019-02-09 20:32:52 +00:00
if (user.displayName != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.displayName;
2019-02-09 21:25:25 +00:00
document.getElementById('newDN').innerHTML = user.displayName;
2019-02-09 20:32:52 +00:00
} else if (user.email != null) {
document.getElementById('status').innerHTML = "You are signed in as: " + user.email;
}
}).catch(function(error) {
if (error.code == 'auth/requires-recent-login') {
alert("Please sign in again to delete your account.")
window.location.href = '../';
} else {
alert("there was a problem: " + error)
}
});
}