angular.module("login", ["ngAnimate"]) .controller("loginController", function ($scope, $http, $location) { var loginErrorMessage = "Login nicht erfolgreich", locationUrl = $location.url(); $scope.user_name = ""; $scope.password = ""; $scope.loading = false; $scope.error = false; $scope.checkLogin = function () { $scope.loading = true; $scope.error = false; $http.post("/login/validate", { user_name: $scope.user_name, password: $scope.password }) .success(function (result) { if (result.success === true) { if (angular.isDefined(locationUrl) && locationUrl) { document.location.href = locationUrl; } else { document.location.href = "/admin"; } } else { $scope.loading = false; $scope.password = ""; $scope.error = true; $scope.errorMessage = loginErrorMessage; } }) .error(function (result) { $scope.error = true; $scope.loading = false; $scope.password = ""; $scope.errorMessage = loginErrorMessage; }); }; });