<commit_before>angular.module('utils.xhr', [])
.service('dataService', function($http, $localStorage, $sessionStorage, GLOBALS) {
  var apiURL = GLOBALS.api_url;
  var sessStorage = $sessionStorage;
  var storage = $localStorage;
  var sessionLock = false;
  
    // delete $http.defaults.headers.common['X-Requested-With'];
    this.getData = function(url, callbackFunc, errCallback) {
      $http({
        method: 'GET',
        url: apiURL + url,
        headers: this.getRequestHeaders()
      }).then(function successCallback(response) {
        callbackFunc(response.data);
      }, function errorCallback(response) {
        if (errCallback && response != undefined) errCallback(response); else console.log("Network Error", response);
      }).$promise;
    }

    this.postData = function(url, params, callbackFunc, errCallback) {
      $http({
        method: 'POST',
        url: apiURL + url,
        data: params,
        headers: this.getRequestHeaders()
      }).then(function successCallback(response) {
        callbackFunc(response.data);
      }, function errorCallback(response) {
        if (errCallback && response != undefined) errCallback(response); else console.log("Network Error", response);
      }).$promise;
    }

    this.putData = function(url, params, callbackFunc, errCallback) {
      $http({
        method: 'PUT',
        url: apiURL + url,
        data: params,
        headers: this.getRequestHeaders()
      }).then(function successCallback(response) {
        callbackFunc(response.data);
      }, function errorCallback(response) {
        if (errCallback && response != undefined) errCallback(response); else console.log("Network Error", response);
      }).$promise;
    }

    this.setAuthToken = function(token) {
      sessStorage.token = <PASSWORD>;
      storage.authToken = (token.remember) ? token.msg : false; // remember me
      this.validateSession();
    }

    this.getRequestHeaders = function() {
      this.validateSession();
      return { 'x-access-token': (sessStorage.token) ? sessStorage.token : "" };
    }

    this.isLoggedIn = function() {
      return sessStorage.token || storage.authToken;
    }

    this.validateSession = function () {
      if (storage.authToken !== undefined){
        sessionLock = true;
        if (storage.authToken) {
          console.log("Dope");
          $http.defaults.headers.common['x-access-token'] = storage.authToken;
          sessStorage.token = storage.authToken;
        }
      } else if (sessionLock) {
          console.log("SessionLock");
          // logout if, logout detected on another browser session
          this.logout();
          sessionLock=false;
        }
      }

      this.logout = function() {
      // invalidate existing token
      $http.get(apiURL+"/authed/tokenRefresh")
      .then(function (data) { 
        /* Do nothing */ 
      }, function (err) {
        console.log("debug", err);
      });
      delete storage.authToken;
      delete sessStorage.authToken;
      delete sessStorage.token;
      // invalidate token on server todo
    }<commit_msg>remove log message<commit_after>angular.module('utils.xhr', [])
.service('dataService', function($http, $localStorage, $sessionStorage, GLOBALS) {
  var apiURL = GLOBALS.api_url;
  var sessStorage = $sessionStorage;
  var storage = $localStorage;
  var sessionLock = false;
  
    // delete $http.defaults.headers.common['X-Requested-With'];
    this.getData = function(url, callbackFunc, errCallback) {
      $http({
        method: 'GET',
        url: apiURL + url,
        headers: this.getRequestHeaders()
      }).then(function successCallback(response) {
        callbackFunc(response.data);
      }, function errorCallback(response) {
        if (errCallback && response != undefined) errCallback(response); else console.log("Network Error", response);
      }).$promise;
    }

    this.postData = function(url, params, callbackFunc, errCallback) {
      $http({
        method: 'POST',
        url: apiURL + url,
        data: params,
        headers: this.getRequestHeaders()
      }).then(function successCallback(response) {
        callbackFunc(response.data);
      }, function errorCallback(response) {
        if (errCallback && response != undefined) errCallback(response); else console.log("Network Error", response);
      }).$promise;
    }

    this.putData = function(url, params, callbackFunc, errCallback) {
      $http({
        method: 'PUT',
        url: apiURL + url,
        data: params,
        headers: this.getRequestHeaders()
      }).then(function successCallback(response) {
        callbackFunc(response.data);
      }, function errorCallback(response) {
        if (errCallback && response != undefined) errCallback(response); else console.log("Network Error", response);
      }).$promise;
    }

    this.setAuthToken = function(token) {
      sessStorage.token = <PASSWORD>;
      storage.authToken = (token.remember) ? token.msg : false; // remember me
      this.validateSession();
    }

    this.getRequestHeaders = function() {
      this.validateSession();
      return { 'x-access-token': (sessStorage.token) ? sessStorage.token : "" };
    }

    this.isLoggedIn = function() {
      return sessStorage.token || storage.authToken;
    }

    this.validateSession = function () {
      if (storage.authToken !== undefined){
        sessionLock = true;
        if (storage.authToken) {
          $http.defaults.headers.common['x-access-token'] = storage.authToken;
          sessStorage.token = storage.authToken;
        }
      } else if (sessionLock) {
          // logout if, logout detected on another browser session
          this.logout();
          sessionLock=false;
        }
      }

      this.logout = function() {
      // invalidate existing token
      $http.get(apiURL+"/authed/tokenRefresh")
      .then(function (data) { 
        /* Do nothing */ 
      }, function (err) {
        console.log("debug", err);
      });
      delete storage.authToken;
      delete sessStorage.authToken;
      delete sessStorage.token;
      // invalidate token on server todo
    }
{'fraction_non_alphanumeric': 0.13120104438642297, 'fraction_numerical': 0.0, 'mean_word_length': 2.615929203539823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1170957', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1685, 'n_words': 366}