<commit_before>(function() {
    'use strict';

    angular
        .module('promort.authentication.services')
        .factory('Authentication', Authentication);

    Authentication.$inject = ['$cookies', '$http', 'ngDialog'];

    function Authentication($cookies, $http, ngDialog) {
        var Authentication = {
            login: login,
            logout: logout,
            checkUser: checkUser,
            isAuthenticated: isAuthenticated,
            setAuthenticationCookie: setAuthenticationCookie,
            unauthenticate: unauthenticate
        };

        return Authentication;

        function login(username, password) {
            return $http.post('/api/auth/login/', {
                username: username, password: password
            }).then(loginSuccessFn, loginErrorFn);
            
            function loginSuccessFn(data, status, header, config) {
                Authentication.setAuthenticationCookie();
                
                window.location = '/worklist';
            }
            
            function loginErrorFn(data, status, headers, config) {
                console.error('Unable to complete login request');

                ngDialog.open({
                    template: '/static/templates/authentication/authentication_error.html'
                });
            }
        }
        
        function logout() {
            console.log('Logout called');
            return $http.post('/api/auth/logout/')
                .then(logoutSuccessFn, logoutErrorFn);
            
            function logoutSuccessFn(data, status, headers, config) {
                Authentication.unauthenticate();
                
                window.location = '/';
            }
            
            function logoutErrorFn(data, status, headers, config) {
                console.error('Error during logout operation');
            }
        }

        function checkUser() {
            return $http.get('api/auth/check/')
                .then(checkSuccessFn, checkErrorFn);

            function checkSuccessFn(data) {
                console.log('Active session found on backed');
                Authentication.setAuthenticationCookie();
            }

            function checkErrorFn(data) {
                console.log('No active session found on backend');
            }
        }

        function isAuthenticated() {
            return !!$cookies.get('promortUserAuthenticated');
        }

        function setAuthenticationCookie() {
            $cookies.putObject('promortUserAuthenticated', true);
        }<commit_msg>added current user to root scope to make it available to all the modules of the application<commit_after>(function() {
    'use strict';

    angular
        .module('promort.authentication.services')
        .factory('Authentication', Authentication);

    Authentication.$inject = ['$cookies', '$http', '$rootScope', 'ngDialog'];

    function Authentication($cookies, $http, $rootScope, ngDialog) {
        var Authentication = {
            login: login,
            logout: logout,
            checkUser: checkUser,
            isAuthenticated: isAuthenticated,
            setAuthenticationCookie: setAuthenticationCookie,
            unauthenticate: unauthenticate
        };

        return Authentication;

        function login(username, password) {
            return $http.post('/api/auth/login/', {
                username: username, password: password
            }).then(loginSuccessFn, loginErrorFn);
            
            function loginSuccessFn(data, status, header, config) {
                Authentication.setAuthenticationCookie();
                $rootScope.current_user = username;
                
                window.location = '/worklist';
            }
            
            function loginErrorFn(data, status, headers, config) {
                console.error('Unable to complete login request');

                ngDialog.open({
                    template: '/static/templates/authentication/authentication_error.html'
                });
            }
        }
        
        function logout() {
            console.log('Logout called');
            return $http.post('/api/auth/logout/')
                .then(logoutSuccessFn, logoutErrorFn);
            
            function logoutSuccessFn(data, status, headers, config) {
                Authentication.unauthenticate();
                delete($rootScope.current_user);
                
                window.location = '/';
            }
            
            function logoutErrorFn(data, status, headers, config) {
                console.error('Error during logout operation');
            }
        }

        function checkUser() {
            return $http.get('api/auth/check/')
                .then(checkSuccessFn, checkErrorFn);

            function checkSuccessFn(data) {
                console.log('Active session found on backed');
                Authentication.setAuthenticationCookie();
            }

            function checkErrorFn(data) {
                console.log('No active session found on backend');
            }
        }

        function isAuthenticated() {
            return !!$cookies.get('promortUserAuthenticated');
        }

        function setAuthenticationCookie() {
            $cookies.putObject('promortUserAuthenticated', true);
        }
{'fraction_non_alphanumeric': 0.09778357235984354, 'fraction_numerical': 0.0, 'mean_word_length': 1.6703132769766285, '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': '6436649', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1210, 'n_words': 255}