angular.module("myApp").controller("loginController", function ($scope, $http, $window, $state) {
    $scope.loginQTVP = function (login) {
        $http({
            method: 'POST',
            url: 'http://localhost:8081/qtvp/login',
            data: angular.toJson($scope.login),
            headers: {
                'Content-Type': 'application/json'
            }
        }).then(successCallback, errorCallback);

        function successCallback(response) {
            $scope.view = response.data;
            if ($scope.view.status == 200&&($scope.view.role=='HR'||$scope.view.role=='Manager'||$scope.view.role=='TeamLead')) {
                $state.go('admin-home');
            }
            if ($scope.view.status == 200&&$scope.view.role=='Member') {
                $state.go('login');
            }

        }

        function errorCallback(error) {
            //error code
            console.log("can't insert data!!");
        }
    }
});