<commit_before>
function LoginCtrl($scope, $rootScope, $location, $http, urls) {

    $scope.username = "";
    $scope.password = "";
    $rootScope.subtitle = "Login";
    
    $scope.login = function(username, password) {
        var data = {
            username: username,
            password: password
        };
        return $http.post(urls.login, data, FORM_ENCODED_POST)
            .success(function(result) {
                if (result.success) {
                    $rootScope.user = result.user;
                    $location.path('/projects');
                } else {
                    $scope.error = result.error;
                }
            });
    };
}

function LoggedInCtrl($scope, $rootScope, $location, $http, urls) {
    
    $scope.logout = function() {
        return $http.post(urls.logout, {}, FORM_ENCODED_POST)
            .success(function() {
                $rootScope.user = null;
                $location.path('/login');
            });
    }
}

function resolveUserOrNull($q, $http, $location, urls) {
    var deferred = $q.defer();
    $http.get(urls.user)
        .success(function(user) {
            if (user == "") {
                user = null;
            }
            deferred.resolve(user);
        })
    return deferred.promise;
}

function resolveUser($rootScope, $q, $http, $location, urls) {
    var deferred = $q.defer();
    resolveUserOrNull($q, $http, $location, urls)
        .then(function(user) {
            $rootScope.user = user;
            if (user != null) {
                deferred.resolve(user);
            } else {
                deferred.reject();
                $location.path('/login');
            }
        });
    return deferred.promise;
}<commit_msg>Show error when login results in an HTTP error<commit_after>
function LoginCtrl($scope, $rootScope, $location, $http, urls) {

    $scope.username = "";
    $scope.password = "";
    $rootScope.subtitle = "Login";
    
    $scope.login = function(username, password) {
        var data = {
            username: username,
            password: password
        };
        return $http.post(urls.login, data, FORM_ENCODED_POST)
            .then(function(result) {
                if (result.data.success) {
                    $rootScope.user = result.data.user;
                    $location.path('/projects');
                } else {
                    $scope.error = result.data.error;
                }
            }, function(error) {
                alert("Error when logging in: ", error.statusText);
                console.log("Couldn't login", error);
            });
    };
}

function LoggedInCtrl($scope, $rootScope, $location, $http, urls) {
    
    $scope.logout = function() {
        return $http.post(urls.logout, {}, FORM_ENCODED_POST)
            .success(function() {
                $rootScope.user = null;
                $location.path('/login');
            });
    }
}

function resolveUserOrNull($q, $http, $location, urls) {
    var deferred = $q.defer();
    $http.get(urls.user)
        .success(function(user) {
            if (user == "") {
                user = null;
            }
            deferred.resolve(user);
        })
    return deferred.promise;
}

function resolveUser($rootScope, $q, $http, $location, urls) {
    var deferred = $q.defer();
    resolveUserOrNull($q, $http, $location, urls)
        .then(function(user) {
            $rootScope.user = user;
            if (user != null) {
                deferred.resolve(user);
            } else {
                deferred.reject();
                $location.path('/login');
            }
        });
    return deferred.promise;
}

{'fraction_non_alphanumeric': 0.14001634432034868, 'fraction_numerical': 0.0, 'mean_word_length': 1.6209850107066381, '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': '6598673', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1042, 'n_words': 197}