<commit_before>/*jshint browser: true */
/*jshint strict: false, unused: false */
/*global window, Backbone, $,_, window, frontendConfig, arangoHelper */

window.ArangoUsers = Backbone.Collection.extend({
  model: window.Users,

  activeUser: null,
  activeUserSettings: {
    "query" : {},
    "shell" : {},
    "testing": true
  },

  sortOptions: {
    desc: false
  },

  url: frontendConfig.basePath + "/_api/user",

  //comparator : function(obj) {
  //  return obj.get("user").toLowerCase();
  //},

  comparator: function(item, item2) {
    var a = item.get('user').toLowerCase();
    var b = item2.get('user').toLowerCase();
    if (this.sortOptions.desc === true) {
      return a < b ? 1 : a > b ? -1 : 0;
    }
    return a > b ? 1 : a < b ? -1 : 0;
  },

  login: function (username, password, callback) {
    var self = this;

    $.ajax({
      url: arangoHelper.databaseUrl("/_open/auth"),
      method: "POST",
      data: JSON.stringify({
        username: username,
        password: password
      }),
      dataType: "json"
    }).success(
      function (data) {
        arangoHelper.setCurrentJwt(data.jwt);
        
        var jwtParts = data.jwt.split('.');
        if (!jwtParts[1]) {
          throw new Error("Invalid JWT");
        }
        
        if (!window.atob) {
          throw new Error("base64 support missing in browser");
        }
        var payload = JSON.parse(atob(jwtParts[1]));

        self.activeUser = payload.preferred_username;
        callback(false, self.activeUser);
      }
    ).error(
      function () {
        arangoHelper.setCurrentJwt(null);
        self.activeUser = null;
        callback(true, null);
      }
    );
  },

  setSortingDesc: function(yesno) {
    this.sortOptions.desc = yesno;
  },

  logout: function () {
    arangoHelper.setCurrentJwt(null);
    this.activeUser = null;
    this.reset();
    window.App.navigate("");
    window.location.reload();
  },

  setUserSettings: function (identifier, content) {
    this.activeUserSettings.identifier = content;
  },

  loadUserSettings: function (callback) {
    var self = this;
    $.ajax({
      type: "GET",
      cache: false,
      url: frontendConfig.basePath + "/_api/user/" + encodeURIComponent(self.activeUser),
      contentType: "application/json",
      processData: false,
      success: function(data) {
        self.activeUserSettings = data.extra;
        callback(false, data);
      },
      error: function(data) {
        callback(true, data);
      }
    });
  },

  saveUserSettings: function (callback) {
    var self = this;
    $.ajax({
      cache: false,
      type: "PUT",
      url: frontendConfig.basePath + "/_api/user/" + encodeURIComponent(self.activeUser),
      data: JSON.stringify({ extra: self.activeUserSettings }),
      contentType: "application/json",
      processData: false,
      success: function(data) {
        callback(false, data);
      },
      error: function(data) {
        callback(true, data);
      }
    });
  },

  parse: function(response)  {
    var result = [];
    _.each(response.result, function(object) {
      result.push(object);
    });
    return result;
  },

  whoAmI: function(callback) {
    if (this.activeUser) {
      callback(false, this.activeUser);
      return;
    }
    $.ajax("whoAmI?_=" + Date.now())
    .success(
      function(data) {
        callback(false, data.user);
      }
    ).error(
      function(data) {
        callback(true, null);
      }
    );
  }


});<commit_msg>web ui users bugfix<commit_after>/*jshint browser: true */
/*jshint strict: false, unused: false */
/*global window, atob, Backbone, $,_, window, frontendConfig, arangoHelper */

window.ArangoUsers = Backbone.Collection.extend({
  model: window.Users,

  activeUser: null,
  activeUserSettings: {
    "query" : {},
    "shell" : {},
    "testing": true
  },

  sortOptions: {
    desc: false
  },

  fetch: function(options) {
    return Backbone.Collection.prototype.fetch.call(this, options);
  },

  url: frontendConfig.basePath + "/_api/user",
  //url: arangoHelper.databaseUrl("/_api/user"),

  //comparator : function(obj) {
  //  return obj.get("user").toLowerCase();
  //},

  comparator: function(item, item2) {
    var a = item.get('user').toLowerCase();
    var b = item2.get('user').toLowerCase();
    if (this.sortOptions.desc === true) {
      return a < b ? 1 : a > b ? -1 : 0;
    }
    return a > b ? 1 : a < b ? -1 : 0;
  },

  login: function (username, password, callback) {
    var self = this;

    $.ajax({
      url: arangoHelper.databaseUrl("/_open/auth"),
      method: "POST",
      data: JSON.stringify({
        username: username,
        password: password
      }),
      dataType: "json"
    }).success(
      function (data) {
        arangoHelper.setCurrentJwt(data.jwt);
        
        var jwtParts = data.jwt.split('.');
        if (!jwtParts[1]) {
          throw new Error("Invalid JWT");
        }
        
        if (!window.atob) {
          throw new Error("base64 support missing in browser");
        }
        var payload = JSON.parse(atob(jwtParts[1]));

        self.activeUser = payload.preferred_username;
        callback(false, self.activeUser);
      }
    ).error(
      function () {
        arangoHelper.setCurrentJwt(null);
        self.activeUser = null;
        callback(true, null);
      }
    );
  },

  setSortingDesc: function(yesno) {
    this.sortOptions.desc = yesno;
  },

  logout: function () {
    arangoHelper.setCurrentJwt(null);
    this.activeUser = null;
    this.reset();
    window.App.navigate("");
    window.location.reload();
  },

  setUserSettings: function (identifier, content) {
    this.activeUserSettings.identifier = content;
  },

  loadUserSettings: function (callback) {
    var self = this;

    $.ajax({
      type: "GET",
      cache: false,
      //url: frontendConfig.basePath + "/_api/user/" + encodeURIComponent(self.activeUser),
      url: arangoHelper.databaseUrl("/_api/user/" + encodeURIComponent(self.activeUser)),
      contentType: "application/json",
      processData: false,
      success: function(data) {
        self.activeUserSettings = data.extra;
        callback(false, data);
      },
      error: function(data) {
        callback(true, data);
      }
    });
  },

  saveUserSettings: function (callback) {
    var self = this;
    $.ajax({
      cache: false,
      type: "PUT",
      url: frontendConfig.basePath + "/_api/user/" + encodeURIComponent(self.activeUser),
      data: JSON.stringify({ extra: self.activeUserSettings }),
      contentType: "application/json",
      processData: false,
      success: function(data) {
        callback(false, data);
      },
      error: function(data) {
        callback(true, data);
      }
    });
  },

  parse: function(response)  {
    var result = [];
    _.each(response.result, function(object) {
      result.push(object);
    });
    return result;
  },

  whoAmI: function(callback) {
    if (this.activeUser) {
      callback(false, this.activeUser);
      return;
    }
    $.ajax("whoAmI?_=" + Date.now())
    .success(
      function(data) {
        callback(false, data.user);
      }
    ).error(
      function() {
        callback(true, null);
      }
    );
  }


});
{'fraction_non_alphanumeric': 0.15121884038011293, 'fraction_numerical': 0.003305329844374053, 'mean_word_length': 2.3434622467771637, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2406562', 'n_tokens_mistral': 2298, 'n_tokens_neox': 2283, 'n_words': 462}