2019-01-06 18:54:08 +00:00
|
|
|
// Initialize Firebase
|
|
|
|
var config = {
|
2019-01-06 19:41:15 +00:00
|
|
|
apiKey: "(insert the TitanScout Api Key Here)",
|
2019-01-06 18:54:08 +00:00
|
|
|
authDomain: "titanscoutandroid.firebaseapp.com",
|
|
|
|
databaseURL: "https://titanscoutandroid.firebaseio.com",
|
|
|
|
projectId: "titanscoutandroid",
|
|
|
|
storageBucket: "titanscoutandroid.appspot.com",
|
|
|
|
messagingSenderId: "1097635313476"
|
|
|
|
};
|
|
|
|
firebase.initializeApp(config);
|
|
|
|
// FirebaseUI config.
|
|
|
|
var uiConfig = {
|
|
|
|
callbacks:{
|
|
|
|
signInSuccessWithAuthResult:function(authResult, redirectUrl) {
|
|
|
|
if (authResult.user) {
|
|
|
|
handleSignedInUser(authResult.user);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//signInSuccessUrl: '<url-to-redirect-to-on-success>',
|
|
|
|
signInOptions: [
|
|
|
|
// Leave the lines as is for the providers you want to offer your users.
|
|
|
|
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
|
|
|
|
//firebase.auth.FacebookAuthProvider.PROVIDER_ID,
|
|
|
|
//firebase.auth.TwitterAuthProvider.PROVIDER_ID,
|
|
|
|
firebase.auth.GithubAuthProvider.PROVIDER_ID,
|
|
|
|
firebase.auth.EmailAuthProvider.PROVIDER_ID,
|
|
|
|
firebase.auth.PhoneAuthProvider.PROVIDER_ID,
|
|
|
|
// firebaseui.auth.AnonymousAuthProvider.PROVIDER_ID
|
|
|
|
],
|
|
|
|
// tosUrl and privacyPolicyUrl accept either url string or a callback
|
|
|
|
// function.
|
|
|
|
// Terms of service url/callback.
|
|
|
|
tosUrl: function(){alert("this is a test app. don't use it");},
|
|
|
|
// Privacy policy url/callback.
|
|
|
|
privacyPolicyUrl: function() {
|
|
|
|
alert("we will steal all of the data");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var handleSignedInUser = function(user) {
|
|
|
|
document.getElementById("mainhead").innerHTML = "TitanScout- Create Form";
|
|
|
|
if (user.displayName != null){
|
|
|
|
document.getElementById('status').innerHTML = "You are signed in as: " + user.displayName;
|
|
|
|
}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;
|
|
|
|
}else{
|
|
|
|
document.getElementById('status').innerHTML = "You are signed in.";
|
|
|
|
}
|
|
|
|
document.getElementById('signout').style.display='inline-block';
|
2019-02-06 19:24:56 +00:00
|
|
|
document.getElementById('updpi').style.display='inline-block';
|
2019-01-06 18:54:08 +00:00
|
|
|
document.getElementById('deleteacc').style.display='inline-block';
|
2019-02-06 20:46:41 +00:00
|
|
|
document.getElementById('profileupd').style.display='none';
|
2019-01-06 18:54:08 +00:00
|
|
|
}
|
|
|
|
var handleSignedOutUser = function() {
|
|
|
|
document.getElementById("mainhead").innerHTML = "TitanScout- Sign In";
|
|
|
|
document.getElementById('status').innerHTML = "You are not signed in.";
|
|
|
|
document.getElementById('signout').style.display='none';
|
2019-02-06 19:24:56 +00:00
|
|
|
document.getElementById('updpi').style.display='none';
|
2019-01-06 18:54:08 +00:00
|
|
|
document.getElementById('deleteacc').style.display='none';
|
2019-02-06 20:46:41 +00:00
|
|
|
document.getElementById('profileupd').style.display='none';
|
2019-01-06 18:54:08 +00:00
|
|
|
ui.start('#firebaseui-auth-container', uiConfig);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Initialize the FirebaseUI Widget using Firebase.
|
|
|
|
var ui = new firebaseui.auth.AuthUI(firebase.auth());
|
|
|
|
|
|
|
|
// The start method will wait until the DOM is loaded.
|
|
|
|
ui.start('#firebaseui-auth-container', uiConfig);
|
|
|
|
var deleteAccount = function() {
|
|
|
|
try {
|
|
|
|
firebase.auth().currentUser.delete()
|
|
|
|
handleSignedOutUser()
|
|
|
|
} catch (error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to delete your account.');
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function signout() {
|
|
|
|
var user = firebase.auth().currentUser;
|
|
|
|
firebase.auth().signOut()
|
|
|
|
handleSignedOutUser()
|
|
|
|
}
|
2019-02-06 19:24:56 +00:00
|
|
|
function loadupdpi(){
|
|
|
|
if(firebase.auth().currentUser != null){
|
2019-02-06 20:15:59 +00:00
|
|
|
document.getElementById('profileupd').style.display='block';
|
2019-02-06 19:24:56 +00:00
|
|
|
}else {
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in to change your account info.');
|
|
|
|
}, 1);
|
2019-02-06 19:57:29 +00:00
|
|
|
handleSignedOutUser();
|
2019-02-06 19:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 20:46:41 +00:00
|
|
|
function upProfileInfo() {
|
|
|
|
if(firebase.auth().currentUser != null){
|
|
|
|
if(document.getElementById('newDN').value != ''){
|
|
|
|
user.updateProfile({
|
|
|
|
displayName: document.getElementById('newDN').value
|
|
|
|
}).then(function() {
|
|
|
|
if (document.getElementById('newPP').value != '') {
|
|
|
|
user.updateProfile({
|
|
|
|
photoURL: document.getElementById('newPP').value
|
|
|
|
}).then(function() {
|
|
|
|
if(document.getElementById('newEM').value != ''){
|
|
|
|
user.updateEmail(document.getElementById('newEM').value).then(function() {
|
|
|
|
handleSignedInUser();
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
handleSignedInUser();
|
|
|
|
}
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
if(document.getElementById('newEM').value != ''){
|
|
|
|
user.updateEmail(document.getElementById('newEM').value).then(function() {
|
|
|
|
handleSignedInUser();
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
handleSignedInUser();}
|
|
|
|
}
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
if (document.getElementById('newPP').value != '') {
|
|
|
|
user.updateProfile({
|
|
|
|
photoURL: document.getElementById('newPP').value
|
|
|
|
}).then(function() {
|
|
|
|
if(document.getElementById('newEM').value != ''){
|
|
|
|
user.updateEmail(document.getElementById('newEM').value).then(function() {
|
|
|
|
handleSignedInUser();
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
handleSignedInUser();
|
|
|
|
}
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
if(document.getElementById('newEM').value != ''){
|
|
|
|
user.updateEmail(document.getElementById('newEM').value).then(function() {
|
|
|
|
handleSignedInUser();
|
|
|
|
}).catch(function(error) {
|
|
|
|
if (error.code == 'auth/requires-recent-login') {
|
|
|
|
// The user's credential is too old. She needs to sign in again.
|
|
|
|
signout()
|
|
|
|
// The timeout allows the message to be displayed after the UI has
|
|
|
|
// changed to the signed out state.
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in again to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
} else {
|
|
|
|
alert("An Error Occurred: "+error.code)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
handleSignedInUser();}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
setTimeout(function() {
|
|
|
|
alert('Please sign in to change your account info.');
|
|
|
|
}, 1);
|
|
|
|
handleSignedOutUser();
|
|
|
|
}
|
|
|
|
}
|