<commit_before>'use strict';

angular.module('IssueTrackingSystem.services.users', [])
    .factory('users', ['$http', '$q', 'BASE_URL', 'header',
        function ($http, $q, BASE_URL, header) {

            function getAllUsers() {
                var deferred = $q.defer();

                $http({
                    method: 'get',
                    url: BASE_URL + 'users',
                    headers: header.authenticationHeader()
                }).then(function (success) {
                    deferred.resolve(success);
                }).then(function (error) {
                    deferred.reject(error);
                });

                return deferred.promise;
            }

            function getCurrentUser() {
                var deferred = $q.defer();

                $http({
                    method: 'get',
                    url: BASE_URL + 'users/me/',
                    headers: header.authenticationHeader()
                }).then(function (success) {
                    deferred.resolve(success);
                }, function (error) {
                    deferred.reject(error);
                });

                return deferred.promise;
            }
            //
            // function makeAdmin(userId) {
            //     getCurrent().then(function (currentUser) {
            //         if (!currentUser.isAdmin) {
            //             console.error('Only admins can do that.');
            //             return;
            //         }
            //
            //         var deferred = $q.defer();
            //         var data = 'UserId=' + userId;
            //         $http.put(BASE_URL + 'users/makeadmin', data, headerService.getAuthAndWWWContentHeader())
            //             .then(function (success) {
            //                 deferred.resolve(success);
            //             }, function (error) {
            //                 deferred.reject(error);
            //             });
            //
            //         return deferred.promise;
            //     }, function (error) {
            //         console.error(error);
            //     });
            // }
            //
            // function changePassword(oldPass, newPass, confirmNewPass) {
            //     if (newPass != confirmNewPass) {
            //         console.error('Passwords do not match.');
            //         return;
            //     }
            //
            //     var deferred = $q.defer();
            //     var data = 'OldPassword=' + oldPass + '&NewPassword=' + newPass + '&ConfirmPassword=' + confirmNewPass;
            //     $http.post(BASE_URL + 'api/Account/ChangePassword', data, headerService.getAuthAndWWWContentHeader())
            //         .then(function (success) {
            //             deferred.resolve(success);
            //         }, function (error) {
            //             deferred.reject(error);
            //         });
            //
            //     return deferred.promise;
            // }

            return {
                getAllUsers : getAllUsers,
                getCurrentUser : getCurrentUser
            };
        }]);<commit_msg>create makeUserAdmin and changePassword functions<commit_after>'use strict';

angular.module('IssueTrackingSystem.services.users', [])
    .factory('users', ['$http', '$q', 'BASE_URL', 'header', '$sessionStorage',
        function ($http, $q, BASE_URL, header, $sessionStorage) {

            function getAllUsers() {
                var deferred = $q.defer();

                $http({
                    method: 'get',
                    url: BASE_URL + 'users',
                    headers: header.authenticationHeader()
                }).then(function (success) {
                    deferred.resolve(success);
                }).then(function (error) {
                    deferred.reject(error);
                });

                return deferred.promise;
            }

            function getCurrentUser() {
                var deferred = $q.defer();

                $http({
                    method: 'get',
                    url: BASE_URL + 'users/me/',
                    headers: header.authenticationHeader()
                }).then(function (success) {
                    deferred.resolve(success);
                }, function (error) {
                    deferred.reject(error);
                });

                return deferred.promise;
            }

            function makeUserAdmin(userId) {
                getCurrent().then(function () {
                    if (!$sessionStorage.isAdmin) {
                        console.error('Only admins can do that.');  //TODO Notification error
                        return;
                    }

                    var deferred = $q.defer();
                    var data = 'UserId=' + userId;
                    $http({
                        method: 'put',
                        url: BASE_URL + 'users/makeadmin',
                        data : data,
                        headers: header.authenticationHeader() + header.getWWWContent()
                    }).then(function (success) {
                        deferred.resolve(success);
                    }, function (error) {
                        deferred.reject(error);
                    });

                    return deferred.promise;
                }, function (error) {
                    console.error(error);
                });
            }

            function changePassword(oldPass, newPass, confirmNewPass) {
                if (newPass != confirmNewPass) {
                    console.error('Passwords do not match.');   //TODO notification
                    return;
                }

                var deferred = $q.defer();
                var data = 'OldPassword=' + oldPass + '&NewPassword=' + newPass + '&ConfirmPassword=' + confirmNewPass;
                $http({
                    method : 'post',
                    url : BASE_URL + 'api/Account/ChangePassword',
                    data : data,
                    headers : header.authenticationHeader() + header.getWWWContent()
                }).then(function (success) {
                    deferred.resolve(success);
                }, function (error) {
                    deferred.reject(error);
                });

                return deferred.promise;
            }

            return {
                getAllUsers : getAllUsers,
                getCurrentUser : getCurrentUser,
                makeUserAdmin : makeUserAdmin,
                changePassword : changePassword
            };
        }]);
{'fraction_non_alphanumeric': 0.11620195930670686, 'fraction_numerical': 0.0, 'mean_word_length': 1.0583126550868487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4550915', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1479, 'n_words': 286}