<commit_before>function User() {
  this.userID = '';
  this.userEmail = '';
  this.userName = '';
  this.userPassword = '';
  this.userArtList = [];
  this.userQuests = [];
}

var artquestUser = new User();

// var ref = firebase.database();

$('#register-button').on('click', function(e) {
  e.preventDefault();
  console.log('Register Button clicked');
  artquestUser.register();
});

$('#sign-in-button').on('click', function(e) {
  e.preventDefault();
  console.log('sign-in Button clicked');
  artquestUser.signIn();
});

$('#sign-out-button').on('click', function(e) {
  e.preventDefault();
  console.log('sign-Out Button clicked');
  artquestUser.signOut();
});

$('#locate-button').on('click', function(e) {
  e.preventDefault();
  console.log('Locate Button clicked');
  getMyLocation(1000);
  // sitesNearMe(1000);
});

User.prototype.register = function() {
  console.log('Registering a new user');
  this.userName = $('#nameInput').val();
  var email = $('#emailInput').val();
  var password = $('#passwordInput').val();
  firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
    //handle errors here
    var errorCode = error.code;
    var errorMessage = error.message;
    console.log('error ', errorMessage);
  });
};

User.prototype.signIn = function() {
  console.log('user sign in');
  var email = $('#emailInput').val();
  var password = $('#passwordInput').val();
  firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
    //handle errors here
    var errorCode = error.code;
    var errorMessage = error.message;
    console.log('error ', errorMessage);
  });
};

User.prototype.signOut = function () {
  firebase.auth().signOut().then(function() {
    // Sign-out successful.
    console.log('user signed out');
    artList.all = [];
    artquestUser.userArtList = [];
    artquestUser.userID = '';
    artquestUser.userName = '';
    artquestUser.userEmail = '';
  }, function(error) {
    // An error happened.
    console.log('error signing out');
  });
};

User.prototype.loadUserData = function () {
  firebase.database().ref('/users/' + userID).once('value').then(function(snapshot) {
    if (snapshot.val() != null ) {
      artquestUser.userArtList = snapshot.val().userArtList;
    }
  });
};

var tempList = [];
getFBDataByKey = function(artID) {
  var user = firebase.auth().currentUser;
  var myRef = firebase.database().ref('/users/' + user.uid + '/fbArtList').child(artID).once('value').then(function(snapshot){
    if (snapshot.val() != null ) {
      console.log(snapshot.val());
    }
  });
};

writeFBDataByKey = function(artID, property, value) {
  var myObj = '{' + property + '"' + value + '"}';
  console.log(myObj);
  var user = firebase.auth().currentUser;
  var myRef = firebase.database().ref('/users/' + user.uid + '/fbArtList').child(artID).child(property).set(value);
};

getFBData = function(){
  tempList = [];
  var user = firebase.auth().currentUser;
  var myRef = firebase.database().ref('/users/' + user.uid + '/fbArtList').once('value').then(function(snapshot){
    if (snapshot.val() != null ) {

      for (var key in snapshot.val()) {
      // skip loop if the property is from prototype
        if (!snapshot.val().hasOwnProperty(key)) continue;

        var obj = snapshot.val()[key];
        tempList.push({artID: key, title: obj.title, latitude: obj.latitude, longitude: obj.longitude});
        // for (var prop in obj) {
        //     // skip loop if the property is from prototype
        //   if(!obj.hasOwnProperty(prop)) continue;
        //     // your code
        //     console.log(prop + " = " + obj[prop]);
        // }
      }
      // console.log(snapshot.val());
    }

  });
};

User.prototype.getUserData = function () {
  var user = firebase.auth().currentUser;
  var userID = user.uid;
  this.userID = user.uid;
  this.userName = user.displayName;
  this.userEmail = user.email;

  firebase.database().ref('/users/' + user.uid + '/userArtList').once('value').then(function(snapshot) {
    if (snapshot.val() === null ) {
      artList.requestList(function(){
        firebase.database().ref('users/' + user.uid).set({
          userArtList: artList.all, userName: user.displayName
        });
        var myRef = firebase.database().ref('/users/' + user.uid);
        artList.all.forEach(function(item, index, array){
          this.child('fbArtList').push(item);
        }, myRef);
        artquestUser.userArtList = artList.all;
        // page('/new+list');
      });
    } else {
      console.log('user.artList exists in firebase DB');
      // console.log(snapshot.val().userArtList);
      artquestUser.userArtList = snapshot.val().userArtList;
      // page('/new+list');
    }
  });
};

User.prototype.getUserQuests = function () {
  var user = firebase.auth().currentUser;

  firebase.database().ref('/users/' + user.uid + '/userQuests').once('value').then(function(snapshot) {
    console.log('inside of User.prototype.getUserQuests');
    console.log(snapshot.val());
    if (!snapshot.val()) {
      console.log('no quests in fb');
      Quest.all = [];
    } else {
      console.log('quest list exists in firebase DB');<commit_msg>prep for merge<commit_after>function User() {
  this.userID = '';
  this.userEmail = '';
  this.userName = '';
  this.userPassword = '';
  this.userArtList = [];
  this.userQuests = [];
}

var artquestUser = new User();

// var ref = firebase.database();

$('#register-button').on('click', function(e) {
  e.preventDefault();
  console.log('Register Button clicked');
  artquestUser.register();
});

$('#sign-in-button').on('click', function(e) {
  e.preventDefault();
  console.log('sign-in Button clicked');
  artquestUser.signIn();
});

$('#sign-out-button').on('click', function(e) {
  e.preventDefault();
  console.log('sign-Out Button clicked');
  artquestUser.signOut();
});

$('#locate-button').on('click', function(e) {
  e.preventDefault();
  console.log('Locate Button clicked');
  getMyLocation(1000);
  // sitesNearMe(1000);
});

User.prototype.register = function() {
  console.log('Registering a new user');
  this.userName = $('#nameInput').val();
  var email = $('#emailInput').val();
  var password = <PASSWORD>();
  firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
    //handle errors here
    var errorCode = error.code;
    var errorMessage = error.message;
    console.log('error ', errorMessage);
  });
};

User.prototype.signIn = function() {
  console.log('user sign in');
  var email = $('#emailInput').val();
  var password = <PASSWORD>').<PASSWORD>();
  firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
    //handle errors here
    var errorCode = error.code;
    var errorMessage = error.message;
    console.log('error ', errorMessage);
  });
};

User.prototype.signOut = function () {
  firebase.auth().signOut().then(function() {
    // Sign-out successful.
    console.log('user signed out');
    artList.all = [];
    artquestUser.userArtList = [];
    artquestUser.userID = '';
    artquestUser.userName = '';
    artquestUser.userEmail = '';
  }, function(error) {
    // An error happened.
    console.log('error signing out');
  });
};

User.prototype.loadUserData = function () {
  firebase.database().ref('/users/' + userID).once('value').then(function(snapshot) {
    if (snapshot.val() != null ) {
      artquestUser.userArtList = snapshot.val().userArtList;
    }
  });
};

var tempList = [];
getFBDataByKey = function(artID) {
  var user = firebase.auth().currentUser;
  var myRef = firebase.database().ref('/users/' + user.uid + '/fbArtList').child(artID).once('value').then(function(snapshot){
    if (snapshot.val() != null ) {
      console.log(snapshot.val());
    }
  });
};

writeFBDataByKey = function(artID, property, value) {
  var myObj = '{' + property + '"' + value + '"}';
  console.log(myObj);
  var user = firebase.auth().currentUser;
  var myRef = firebase.database().ref('/users/' + user.uid + '/fbArtList').child(artID).child(property).set(value);
};

getFBData = function(){
  tempList = [];
  var user = firebase.auth().currentUser;
  var myRef = firebase.database().ref('/users/' + user.uid + '/fbArtList').once('value').then(function(snapshot){
    if (snapshot.val() != null ) {

      for (var key in snapshot.val()) {
      // skip loop if the property is from prototype
        if (!snapshot.val().hasOwnProperty(key)) continue;

        var obj = snapshot.val()[key];
        tempList.push({artID: key, title: obj.title, latitude: obj.latitude, longitude: obj.longitude});
        // for (var prop in obj) {
        //     // skip loop if the property is from prototype
        //   if(!obj.hasOwnProperty(prop)) continue;
        //     // your code
        //     console.log(prop + " = " + obj[prop]);
        // }
      }
      // console.log(snapshot.val());
    }

  });
  // return tempList;
};

User.prototype.getUserData = function () {
  var user = firebase.auth().currentUser;
  var userID = user.uid;
  this.userID = user.uid;
  this.userName = user.displayName;
  this.userEmail = user.email;

  firebase.database().ref('/users/' + user.uid + '/userArtList').once('value').then(function(snapshot) {
    if (snapshot.val() === null ) {
      artList.requestList(function(){
        firebase.database().ref('users/' + user.uid).set({
          userArtList: artList.all, userName: user.displayName
        });
        var myRef = firebase.database().ref('/users/' + user.uid);
        artList.all.forEach(function(item, index, array){
          this.child('fbArtList').push(item);
        }, myRef);
        artquestUser.userArtList = artList.all;
        // page('/new+list');
      });
    } else {
      console.log('user.artList exists in firebase DB');
      // console.log(snapshot.val().userArtList);
      artquestUser.userArtList = snapshot.val();
      // page('/new+list');
    }
  });
};

User.prototype.getUserQuests = function () {
  var user = firebase.auth().currentUser;

  firebase.database().ref('/users/' + user.uid + '/userQuests').once('value').then(function(snapshot) {
    console.log('inside of User.prototype.getUserQuests');
    console.log(snapshot.val());
    if (!snapshot.val()) {
      console.log('no quests in fb');
      Quest.all = [];
    } else {
      console.log('quest list exists in firebase DB');
{'fraction_non_alphanumeric': 0.18774056966897615, 'fraction_numerical': 0.001539645881447267, 'mean_word_length': 3.2629204265791634, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2191391', 'n_tokens_mistral': 3258, 'n_tokens_neox': 3274, 'n_words': 589}