<commit_before>"use strict";

var services = angular.module('smlBootstrap.services', ['ngResource']);

var dontBlockOnAjaxHeader = { "dontBlockPageOnAjax": "true" };
var nonArrayGetWithoutBlockOnAjax = { method: "GET", isArray: false, headers: dontBlockOnAjaxHeader };



services.factory('EntriesService', function ($resource) {

    var self = this;

    self.entriesCrudResource = $resource('rest/entries/:id', { }, {
        insert: { method: "PUT"},
        query: nonArrayGetWithoutBlockOnAjax
    });

    self.counterResource = $resource("/rest/entries/count", { }, {
        get: nonArrayGetWithoutBlockOnAjax
    });

    self.newEntriesCounterResource = $resource("/rest/entries/count-newer/:time", { }, {
        get: nonArrayGetWithoutBlockOnAjax
    });

    var entriesService = {};

    entriesService.loadAll = function (successFunction) {
        self.entriesCrudResource.query(null, successFunction);
    };

    entriesService.addNew = function (entryText, successFunction) {
        var json = {};
        json.text = entryText;
        self.entriesCrudResource.save(angular.toJson(json), successFunction);
    };

    entriesService.load = function (logObjectId, successFunction) {
        self.entriesCrudResource.get({id: logObjectId}, successFunction);
    };

    entriesService.update = function (logObject) {
        var json = {};
        json.text = logObject.text;
        json.id = logObject.id;
        self.entriesCrudResource.insert(angular.toJson(json));
    };

    entriesService.deleteEntry = function (logObjectId, successFunction) {
        self.entriesCrudResource.remove({id: logObjectId}, successFunction);
    };

    entriesService.count = function (successFunction) {
        self.counterResource.get(successFunction);
    };

    entriesService.countNewEntries = function (timestamp, successFunction) {
        self.newEntriesCounterResource.get({time: timestamp}, successFunction);
    };

    return entriesService;
});


services.factory('UserSessionService', function ($resource) {

    var self = this;

    self.userResource = $resource('rest/users/', { }, {
        login: {method: 'POST'},
        valid: {method: 'GET'}
    });

    self.logoutResource = $resource('rest/users/logout', { }, { });


    var userSessionService = {
        loggedUser: null
    };

    userSessionService.isLogged = function () {
        return userSessionService.loggedUser !== null;
    };

    userSessionService.isNotLogged = function () {
        return userSessionService.loggedUser === null;
    };

    userSessionService.login = function (user, successFunction, errorFunction) {
        self.userResource.login(angular.toJson(user), function (data) {
            userSessionService.loggedUser = data;
            if (typeof successFunction === "function") {
                successFunction(data);
            }
        }, errorFunction);
    };

    userSessionService.logout = function (user, successFunction) {
        self.logoutResource.query(null, function (data) {
            userSessionService.loggedUser = null;
            if (typeof successFunction === "function") {
                successFunction(data);
            }
        });
    };

    userSessionService.validate = function (successFunction) {
        self.userResource.valid(function (data) {
            userSessionService.loggedUser = data;
            if (typeof successFunction === "function") {
                successFunction(data);
            }
        });
    };

    userSessionService.getLoggedUserName = function () {
        if (userSessionService.loggedUser) {
            return userSessionService.loggedUser.login;
        } else {
            return "";
        }
    };

    return userSessionService;
});


services.factory('UtilService', function ($resource) {

    var self = this;

    self.utilResource = $resource('/rest/uptime', { }, {
        get: nonArrayGetWithoutBlockOnAjax
    });

    var utilService = {};

    utilService.loadUptime = function (successFunction) {
        return self.utilResource.get(successFunction);
    };

    return utilService;
});

services.factory('RegisterService', function ($resource, FlashService) {

    var self = this;
    self.registerResource = $resource('rest/users/register');

    var registerService = {};

    registerService.register = function (user, successFunction, errorFunction) {
        self.registerResource.save(angular.toJson(user), function (data) {
            if (angular.equals(data.value, 'success')) {
                FlashService.set("User registered successfully! Please check your e-mail for confirmation.");
                successFunction();
            } else {
                errorFunction(data.value);
            }
        });
    };

    return registerService;
});

services.factory("FlashService", function () {

    var queue = [];

    return {
        set: function (message) {
            queue.push(message);
        },
        get: function () {
            return queue.shift();
        }
    };
});<commit_msg>#24 Create page for user to enter e-mail or login for password recovery<commit_after>"use strict";

var services = angular.module('smlBootstrap.services', ['ngResource']);

var dontBlockOnAjaxHeader = { "dontBlockPageOnAjax": "true" };
var nonArrayGetWithoutBlockOnAjax = { method: "GET", isArray: false, headers: dontBlockOnAjaxHeader };


services.factory('EntriesService', function ($resource) {

    var self = this;

    self.entriesCrudResource = $resource('rest/entries/:id', { }, {
        insert: { method: "PUT"},
        query: nonArrayGetWithoutBlockOnAjax
    });

    self.counterResource = $resource("/rest/entries/count", { }, {
        get: nonArrayGetWithoutBlockOnAjax
    });

    self.newEntriesCounterResource = $resource("/rest/entries/count-newer/:time", { }, {
        get: nonArrayGetWithoutBlockOnAjax
    });

    var entriesService = {};

    entriesService.loadAll = function (successFunction) {
        self.entriesCrudResource.query(null, successFunction);
    };

    entriesService.addNew = function (entryText, successFunction) {
        var json = {};
        json.text = entryText;
        self.entriesCrudResource.save(angular.toJson(json), successFunction);
    };

    entriesService.load = function (logObjectId, successFunction) {
        self.entriesCrudResource.get({id: logObjectId}, successFunction);
    };

    entriesService.update = function (logObject) {
        var json = {};
        json.text = logObject.text;
        json.id = logObject.id;
        self.entriesCrudResource.insert(angular.toJson(json));
    };

    entriesService.deleteEntry = function (logObjectId, successFunction) {
        self.entriesCrudResource.remove({id: logObjectId}, successFunction);
    };

    entriesService.count = function (successFunction) {
        self.counterResource.get(successFunction);
    };

    entriesService.countNewEntries = function (timestamp, successFunction) {
        self.newEntriesCounterResource.get({time: timestamp}, successFunction);
    };

    return entriesService;
});


services.factory('UserSessionService', function ($resource) {

    var self = this;

    self.userResource = $resource('rest/users/', { }, {
        login: {method: 'POST'},
        valid: {method: 'GET'}
    });

    self.logoutResource = $resource('rest/users/logout', { }, { });


    var userSessionService = {
        loggedUser: null
    };

    userSessionService.isLogged = function () {
        return userSessionService.loggedUser !== null;
    };

    userSessionService.isNotLogged = function () {
        return userSessionService.loggedUser === null;
    };

    userSessionService.login = function (user, successFunction, errorFunction) {
        self.userResource.login(angular.toJson(user), function (data) {
            userSessionService.loggedUser = data;
            if (typeof successFunction === "function") {
                successFunction(data);
            }
        }, errorFunction);
    };

    userSessionService.logout = function (user, successFunction) {
        self.logoutResource.query(null, function (data) {
            userSessionService.loggedUser = null;
            if (typeof successFunction === "function") {
                successFunction(data);
            }
        });
    };

    userSessionService.validate = function (successFunction) {
        self.userResource.valid(function (data) {
            userSessionService.loggedUser = data;
            if (typeof successFunction === "function") {
                successFunction(data);
            }
        });
    };

    userSessionService.getLoggedUserName = function () {
        if (userSessionService.loggedUser) {
            return userSessionService.loggedUser.login;
        } else {
            return "";
        }
    };

    userSessionService.beginResetProcess = function (login, onComplete) {
        console.log("userSessionService.beginResetProcess")
        onComplete()
    }

    return userSessionService;
});


services.factory('UtilService', function ($resource) {

    var self = this;

    self.utilResource = $resource('/rest/uptime', { }, {
        get: nonArrayGetWithoutBlockOnAjax
    });

    var utilService = {};

    utilService.loadUptime = function (successFunction) {
        return self.utilResource.get(successFunction);
    };

    return utilService;
});

services.factory('RegisterService', function ($resource, FlashService) {

    var self = this;
    self.registerResource = $resource('rest/users/register');

    var registerService = {};

    registerService.register = function (user, successFunction, errorFunction) {
        self.registerResource.save(angular.toJson(user), function (data) {
            if (angular.equals(data.value, 'success')) {
                FlashService.set("User registered successfully! Please check your e-mail for confirmation.");
                successFunction();
            } else {
                errorFunction(data.value);
            }
        });
    };

    return registerService;
});

services.factory("FlashService", function () {

    var queue = [];

    return {
        set: function (message) {
            queue.push(message);
        },
        get: function () {
            return queue.shift();
        }
    };
});


services.factory("PasswordRecoveryService", function() {
    var passwordRecoveryService = {};

    passwordRecoveryService.beginResetProcess = function (login, onComplete) {
        console.log("PasswordRecoveryService.beginResetProcess");
        onComplete();
    };

    return passwordRecoveryService;
});
{'fraction_non_alphanumeric': 0.12280867106503299, 'fraction_numerical': 0.00018850141376060322, 'mean_word_length': 2.732325008793528, 'pattern_counts': {'":': 2, '<': 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': '2225100', 'n_tokens_mistral': 2859, 'n_tokens_neox': 2766, 'n_words': 516}