<commit_before>'use strict';

angular.module('arachne.services')

// singleton service for authentication, stores credentials in browser cookie
// if cookie is present the stored credentials get sent with every backend request
.factory('authService', ['$http', 'arachneSettings', '$filter', '$cookieStore',
function($http, arachneSettings, $filter, $cookieStore) {

    // initialize to whatever is in the cookie, if anything
    if ($cookieStore.get('ar-authdata')) {
        $http.defaults.headers.common['Authorization'] = 'Basic ' + $cookieStore.get('ar-authdata');
    } else {
        delete $http.defaults.headers.common['Authorization'];
    }

    return {

        setCredentials: function (username, password, successMethod, errorMethod) {
            var encoded = $filter('base64')(username + ':' + $filter('md5')(password));
            $http.get(arachneSettings.dataserviceUri + '/userinfo/'+username, { headers: { 'Authorization': 'Basic ' + encoded } })
                .success(function(response) {

                    $http.defaults.headers.common.Authorization = 'Basic ' + encoded;
                    $cookieStore.put('ar-authdata', encoded);
                    $cookieStore.put('ar-user', { username: username });

                    if (response.datasetGroups !== undefined) {
                        $cookieStore.put('ar-datasetgroups', response.datasetGroups);
                    }
                    
                    successMethod();
                }).error(function(response) {
                    errorMethod(response);
                });
        },

        clearCredentials: function () {
            document.execCommand("ClearAuthenticationCache");
            $cookieStore.remove('ar-authdata');
            $cookieStore.remove('ar-user');
            $cookieStore.remove('ar-datasetgroups');
            delete $http.defaults.headers.common['Authorization'];
        },

        getUser: function() {
            return $cookieStore.get('ar-user');
        },

        getDatasetGroups: function() {
            return $cookieStore.get('ar-datasetgroups') || [];
        }
<commit_msg>Ensure that property "datasetGroups" exists before working with it.<commit_after>'use strict';

angular.module('arachne.services')

// singleton service for authentication, stores credentials in browser cookie
// if cookie is present the stored credentials get sent with every backend request
.factory('authService', ['$http', 'arachneSettings', '$filter', '$cookieStore',
function($http, arachneSettings, $filter, $cookieStore) {

    // initialize to whatever is in the cookie, if anything
    if ($cookieStore.get('ar-authdata')) {
        $http.defaults.headers.common['Authorization'] = 'Basic ' + $cookieStore.get('ar-authdata');
    } else {
        delete $http.defaults.headers.common['Authorization'];
    }

    return {

        setCredentials: function (username, password, successMethod, errorMethod) {
            var encoded = $filter('base64')(username + ':' + $filter('md5')(password));
            $http.get(arachneSettings.dataserviceUri + '/userinfo/'+username, { headers: { 'Authorization': 'Basic ' + encoded } })
                .success(function(response) {

                    $http.defaults.headers.common.Authorization = 'Basic ' + encoded;
                    $cookieStore.put('ar-authdata', encoded);
                    $cookieStore.put('ar-user', { username: username });

                    if (response.datasetGroups !== undefined) {
                        $cookieStore.put('ar-datasetgroups', response.datasetGroups);
                    }

                    successMethod();
                }).error(function(response) {
                    errorMethod(response);
                });
        },

        clearCredentials: function () {
            document.execCommand("ClearAuthenticationCache");
            $cookieStore.remove('ar-authdata');
            $cookieStore.remove('ar-user');
            $cookieStore.remove('ar-datasetgroups');
            delete $http.defaults.headers.common['Authorization'];
        },

        getUser: function() {
            return $cookieStore.get('ar-user');
        },

        getDatasetGroups: function() {
            return $cookieStore.get('ar-datasetgroups') || [];
        }

{'fraction_non_alphanumeric': 0.1366387337057728, 'fraction_numerical': 0.0013966480446927375, 'mean_word_length': 2.3413685847589423, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7107156', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1043, 'n_words': 210}