AuthenticationService.js 4 KB
AIA.factory('AuthenticationService', function ($http, $q, $rootScope, LoginConstants) {
    return {
        authenticateUser: function (userInfo) {
            var deferred = $q.defer();
            
            $http.post('/API/api/Authenticate', JSON.stringify(userInfo), {
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .success(function (data, status, headers, config) {
                console.log('success')
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                console.log('error')
                deferred.reject(data);
                    $rootScope.isVisibleLogin = true;
                    $rootScope.errorMessage = data;
                    $("#messageModal").modal('show');
                
            });
            return deferred.promise;
        },

        SendMailToUser: function (userInfo, havePassword) {
            var deferred = $q.defer();

            $http.post('/API/api/ForgotUser', userInfo, { //JSON.stringify(userEmail)
                headers: {
                    'Content-Type': 'application/json'
                }
            })
        .success(function (data, status, headers, config) {
            console.log('success');
            deferred.resolve(data);
        }).error(function (data, status, headers, config) {
            console.log('error')
            deferred.reject(data);

            $rootScope.isVisibleLogin = true;
            $rootScope.errorMessage = data;
            $("#messageModal").modal('show');
        });
            return deferred.promise;
        },

        ResetUserPassword: function (userInfo) {
            var deferred = $q.defer();

            $http.post('/API/api/ResetPassword', JSON.stringify(userInfo), {
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .success(function (data, status, headers, config) {
                console.log('success')
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                console.log('error')
                deferred.reject(data);
                
                $rootScope.isVisibleLogin = true;
                $rootScope.errorMessage = data;
                $("#messageModal").modal('show');
            });
            return deferred.promise;
        },

        UpdateLicenseTerm: function (licenseeAccountNumber) {
            var deferred = $q.defer();

            $http.post('/API/api/LicenseTermCondition', JSON.stringify(licenseeAccountNumber), {
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .success(function (data, status, headers, config) {
                console.log('success')
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                console.log('error')
                deferred.reject(data);
               
                $rootScope.isVisibleLogin = true;
                $rootScope.errorMessage = data;
                $("#messageModal").modal('show');
            });
            return deferred.promise;
        },

        UnblockUser: function (userEmailId) {
            var deferred = $q.defer();

            $http.post('/API/api/UnblockUser', JSON.stringify(userEmailId), {
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .success(function (data, status, headers, config) {
                console.log('success')
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                console.log('error')
                deferred.reject(data);
               
                $rootScope.isVisibleLogin = true;
                $rootScope.errorMessage = data;
                $("#messageModal").modal('show');
            });
            return deferred.promise;
        }

    }
});