<commit_before>/*jslint browser: true */
'use strict';

angular.module('paperchaseApp')
    .factory('UserServices', ['$http', '$cookieStore', '$base64', '$cookies', function ($http, $cookieStore, $base64, $cookies) {
        var user = {isLogged: false, firstLogin: true },
            authData = $cookieStore.get('authdata'),
            firstLogin = $cookieStore.get('firstLogin');

        if (authData) {
            // initialize to whatever is in the cookie, if anything
            $http.defaults.headers.common['Authorization'] = 'Basic ' + authData;
            user.isLogged = true;
        }

        if (firstLogin !== undefined) {
            user.firstLogin = false;
        }

        $http.defaults.headers.post['X-CSRFToken'] = $cookies['_csrf_token'];
        $http.defaults.headers.delete = { 'X-CSRFToken' : $cookies['_csrf_token'] };

        return {
            verifyCredentials: function (username, password) {
                var encoded = $base64.encode(username + ':' + password),
                    apiAddress = '/api/users';
                return $http({method: 'GET', url: apiAddress, headers: {'Authorization': 'Basic '.concat(encoded)}});
            },
            setCredentials: function (username, password) {
                var encoded = $base64.encode(username + ':' + password);
               $http.defaults.headers.common.Authorization = 'Basic ' + encoded;
                user.isLogged = true;
                $cookieStore.put('authdata', encoded);
                if (user.firstLogin === true) {
                    $cookieStore.put('firstLogin', false);
                }
            },
            clearCredentials: function () {
                document.execCommand("ClearAuthenticationCache");
                $http.defaults.headers.common.Authorization = 'Basic ';
                user.isLogged = false;
                $cookieStore.remove('authdata');
            },
            isLogged: function () {
                return user.isLogged;
            },
            hasLoggedInBefore: function () {
                return !user.firstLogin;
            }
        };
    }]);<commit_msg>Switched to saving the token instead of the user credentials onto angular token<commit_after>/*jslint browser: true */
'use strict';

angular.module('paperchaseApp')
    .factory('UserServices', ['$http', '$cookieStore', '$base64', '$cookies', function ($http, $cookieStore, $base64, $cookies) {
        var user = {isLogged: false, firstLogin: true },
            authData = $cookieStore.get('authdata'),
            firstLogin = $cookieStore.get('firstLogin');

        if (authData) {
            // initialize to whatever is in the cookie, if anything
            $http.defaults.headers.common['Authorization'] = 'Basic ' + authData;
            user.isLogged = true;
        }

        if (firstLogin !== undefined) {
            user.firstLogin = false;
        }

        $http.defaults.headers.post['X-CSRFToken'] = $cookies['_csrf_token'];
        $http.defaults.headers.delete = { 'X-CSRFToken' : $cookies['_csrf_token'] };

        return {
            verifyCredentials: function (username, password) {
                var encoded = $base64.encode(username + ':' + password),
                    apiAddress = '/api/users';
                return $http({method: 'GET', url: apiAddress, headers: {'Authorization': 'Basic '.concat(encoded)}});
            },
            setCredentials: function (username, password) {
                var encoded = $base64.encode(username + ':' + password),
                    apiAddress = '/api/users/token';
                $http({method: 'GET', url: apiAddress, headers: {'Authorization': 'Basic '.concat(encoded)}}).
                success(function (data) {
                    encoded = $base64.encode(data.token + ':unused')
                    $http.defaults.headers.common.Authorization = 'Basic ' + encoded;
                    user.isLogged = true;
                    $cookieStore.put('authdata', encoded);
                    $cookieStore.put('authexpire', data.duration);
                    if (user.firstLogin === true) {
                        $cookieStore.put('firstLogin', false);
                    }
                }).
                error();
            },
            clearCredentials: function () {
                document.execCommand("ClearAuthenticationCache");
                $http.defaults.headers.common.Authorization = 'Basic ';
                user.isLogged = false;
                $cookieStore.remove('authdata');
            },
            isLogged: function () {
                return user.isLogged;
            },
            hasLoggedInBefore: function () {
                return !user.firstLogin;
            }
        };
    }]);
{'fraction_non_alphanumeric': 0.1354472910541789, 'fraction_numerical': 0.0037799244015119695, 'mean_word_length': 1.8200118413262285, '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': '2541921', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1210, 'n_words': 246}