loginpanel.js

angular.module('homepage').
directive('loginpanel', function() {
    return {
        controller: 'loginPanelController',
        restrict: 'E',
        replace: true,
        transclude: true,
        templateUrl: 'components/content-components/login/loginpanel.html'
    };
}).
controller('loginPanelController', function($scope, $timeout, $window, Authentication, Server) {
    $scope.isMessageVisible = false;

    $scope.authenticate = function() {
        var user = {
            username: $scope.username,
            password: $scope.password
        };
        Server.login(user).
        success(function(data) {
            console.log(data);
            if(data.token && data.success) {
                Authentication.setUser(data.token);
                Authentication.setHeaders();
                $window.location.href = '/#/home';
            }
            else {
                $scope.message = data.message;
                $scope.isMessageVisible = true;
                $timeout(function () {
                    $scope.isMessageVisible = false;
                }, 3000);
            }
        });
    };
});