(function(){
    angular.module('ctfApp').controller('LoginController',
        ['$scope', '$rootScope', '$location', 'AuthenticationService', '$window',
            function ($scope, $rootScope, $location, AuthenticationService, $window) {
                // reset login status
                AuthenticationService.clearCredentials();

                $scope.login = function () {
                    $scope.dataLoading = true;
                    AuthenticationService.login($scope.username, $scope.password, function(response) {
                        if(response.status == 200) {
                        //todo: put credentials here
                             $window.location.href = "http://gpietrus1:gpietrus@localhost:8080/api/v1/auth";
                             //todo: commeneted temporarily
//                             $window.location.href = "http://gpietrus1:gpietrus@localhost:8080/api/v1/auth";
//                            AuthenticationService.setCredentials($scope.username, $scope.password, response.team);
//                            $('.title').html($scope.username+'@<b>capture-the-flAGH-2016</b>:~$');
//                            $location.path('/');
                        } else {
                            $scope.error = response.message;
                            $scope.dataLoading = false;
                        }
                    });
                };


            }]);
})();