<commit_before>//===========================================================================
//    Copyright 2014 Delving B.V.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
//===========================================================================

define(["angular", "common"], function (angular) {
    "use strict";

    function buildUrls(user) {
        user.narthexAPI = user.narthexDomain + '/narthex/api/' + user.apiKey;
//        console.log("user", user);
    }

    var mod = angular.module("dashboard.services", ["narthex.common"]);
    mod.factory(
        "userService",
        ["$http", "$q", "playRoutes",
            function ($http, $q, playRoutes) {
                var user;
                var main = playRoutes.web.MainController;
                return {
                    logout: function () {
                        console.log("Attempt logout");
                        return main.logout().get().then(function (response) {
                            user = undefined;
                            return "logged out"
                        });
                    },
                    checkLogin: function () {
                        console.log("Check login");
                        return main.jsRoutes().get().then(
                            function (response) {
                                user = {
                                    username: "admin",
                                    apiKey: "foo"
                                };
                                buildUrls(user);
                                return user;
                            });
                    },
                    getUser: function () {
                        return user;
                    }
                };
            }
        ]
    );

    /**
     * Add this object to a route definition to only allow resolving the route if the user is
     * logged in. This also adds the contents of the objects as a dependency of the controller.
     */
    mod.constant("userResolve", {
        user: function ($q, userService) {
            var deferred = $q.defer();
            var user = userService.getUser();<commit_msg>Remove pointless call because I did not know how to return an immediately returning-promise in Angular < 1.4<commit_after>//===========================================================================
//    Copyright 2014 Delving B.V.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
//===========================================================================

define(["angular", "common"], function (angular) {
    "use strict";

    function buildUrls(user) {
        user.narthexAPI = user.narthexDomain + '/narthex/api/' + user.apiKey;
//        console.log("user", user);
    }

    var mod = angular.module("dashboard.services", ["narthex.common"]);
    mod.factory(
        "userService",
        ["$http", "$q", "playRoutes",
            function ($http, $q, playRoutes) {
                var user;
                var main = playRoutes.web.MainController;
                return {
                    logout: function () {
                        console.log("Attempt logout");
                        return main.logout().get().then(function (response) {
                            user = undefined;
                            return "logged out"
                        });
                    },
                    checkLogin: function () {
                        console.log("Check login");
                        return $q.when(true).then(
                            function (response) {
                                user = {
                                    username: "admin",
                                    apiKey: "foo"
                                };
                                buildUrls(user);
                                return user;
                            });
                    },
                    getUser: function () {
                        return user;
                    }
                };
            }
        ]
    );

    /**
     * Add this object to a route definition to only allow resolving the route if the user is
     * logged in. This also adds the contents of the objects as a dependency of the controller.
     */
    mod.constant("userResolve", {
        user: function ($q, userService) {
            var deferred = $q.defer();
            var user = userService.getUser();
{'fraction_non_alphanumeric': 0.14862652355830452, 'fraction_numerical': 0.003274513370929598, 'mean_word_length': 1.401922236784622, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7554112', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1201, 'n_words': 399}