<commit_before>/*!
Cloud4all Preferences Management Tools

Copyright 2013 CERTH/HIT

Licensed under the New BSD license. You may not use this file except in
compliance with this License.

You may obtain a copy of the License at
https://github.com/GPII/prefsEditors/LICENSE.txt
*/

/*global fluid, jQuery, gpii*/
/*jslint white: true, onevar: true, funcinvoke: true, forvar: true, undef: true, newcap: true, nomen: true, regexp: true, plusplus: true, bitwise: true, maxerr: 50, indent: 4 */

(function ($, fluid) {

    fluid.registerNamespace("gpii.prefs");

    /**
     * gpiiSession Subcomponent that holds GPII session information.
     * It holds user token, performs login/logout and generates events for such actions.
     */
    fluid.defaults("gpii.prefs.gpiiSession", {
        gradeNames: ["fluid.eventedComponent", "autoInit"],
        url: "http://localhost:8081/user/",
        // Maybe we should be informed for currently logged user from GPII?
        // This is relevant, http://issues.gpii.net/browse/GPII-290
        loggedUser: null,
        events: {
            onLogin: null,
            onLogout: null,
            accountCreated: null
        },
        invokers: {
            login: {
                "funcName": "gpii.prefs.gpiiSession.login",
                "args": ["{that}", "{arguments}.0"]
            },
            logout: {
                "funcName": "gpii.prefs.gpiiSession.logout",
                "args": ["{that}"]
            }
        },
        listeners: {
            "accountCreated.loginUser": {
                "listener": "{that}.login"
            }
        }
    });

    // make this component globally public through {gpiiSession}
    gpii.prefs.gpiiSession.finalInit = function (that) {
        fluid.staticEnvironment.gpiiSession = that;
    };

    gpii.prefs.gpiiSession.login = function (that, userToken) {
        if (userToken != null) {
            $.ajax({
                url: that.options.url + userToken + "/login",
                type: "GET",
                // NOTE: This is async because we want to serially streamline the logout/login that is triggered
                // by the GPIIStore "refresh" of system level applications when setting preferences.
                async: false,
                /*xhrFields: {
                    withCredentials: true
                },*/
                success: function (data) {
                    that.options.loggedUser = userToken;
                    that.events.onLogin.fire();
                    fluid.log("GET: " + data);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    fluid.log("GET: Error at logging in user " + userToken + "! Test status: " + textStatus);
                    fluid.log(errorThrown);
                }
            });
        }
    };

    gpii.prefs.gpiiSession.logout = function (that) {
        if (that.options.loggedUser != null) {
            $.ajax({
                url: that.options.url + that.options.loggedUser + "/logout",
                type: "GET",
                // NOTE: This is async because we want to serially streamline the logout/login that is triggered
                // by the GPIIStore "refresh" of system level applications when setting preferences.
                async: false,
                /*xhrFields: {
                    withCredentials: true
                },*/
                success: function (data) {
                    that.options.loggedUser = null;
                    that.events.onLogout.fire();
                    fluid.log("GET: " + data);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    fluid.log("GET: Error at logging out user " + that.options.loggedUser + "! Test status: " + textStatus);
                    fluid.log(errorThrown);
                }
            });
        }
    };

})(jQuery, fluid);<commit_msg>GPII-547: Corrected some comments.<commit_after>/*!
Cloud4all Preferences Management Tools

Copyright 2013 CERTH/HIT

Licensed under the New BSD license. You may not use this file except in
compliance with this License.

You may obtain a copy of the License at
https://github.com/GPII/prefsEditors/LICENSE.txt
*/

/*global fluid, jQuery, gpii*/
/*jslint white: true, onevar: true, funcinvoke: true, forvar: true, undef: true, newcap: true, nomen: true, regexp: true, plusplus: true, bitwise: true, maxerr: 50, indent: 4 */

(function ($, fluid) {

    fluid.registerNamespace("gpii.prefs");

    /**
     * gpiiSession Subcomponent that holds GPII session information.
     * It holds user token, performs login/logout and generates events for such actions.
     */
    fluid.defaults("gpii.prefs.gpiiSession", {
        gradeNames: ["fluid.eventedComponent", "autoInit"],
        url: "http://localhost:8081/user/",
        // Maybe we should be informed for currently logged user from GPII?
        // This is relevant, http://issues.gpii.net/browse/GPII-290
        loggedUser: null,
        events: {
            onLogin: null,
            onLogout: null,
            accountCreated: null
        },
        invokers: {
            login: {
                "funcName": "gpii.prefs.gpiiSession.login",
                "args": ["{that}", "{arguments}.0"]
            },
            logout: {
                "funcName": "gpii.prefs.gpiiSession.logout",
                "args": ["{that}"]
            }
        },
        listeners: {
            "accountCreated.loginUser": {
                "listener": "{that}.login"
            }
        }
    });

    // make this component globally public through {gpiiSession}
    gpii.prefs.gpiiSession.finalInit = function (that) {
        fluid.staticEnvironment.gpiiSession = that;
    };

    gpii.prefs.gpiiSession.login = function (that, userToken) {
        if (userToken != null) {
            $.ajax({
                url: that.options.url + userToken + "/login",
                type: "GET",
                // NOTE: This is non-async because we want to serially streamline the logout/login that is triggered
                // by the GPIIStore "refresh" of system level applications when setting preferences.
                async: false,
                /*xhrFields: {
                    withCredentials: true
                },*/
                success: function (data) {
                    that.options.loggedUser = userToken;
                    that.events.onLogin.fire();
                    fluid.log("GET: " + data);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    fluid.log("GET: Error at logging in user " + userToken + "! Test status: " + textStatus);
                    fluid.log(errorThrown);
                }
            });
        }
    };

    gpii.prefs.gpiiSession.logout = function (that) {
        if (that.options.loggedUser != null) {
            $.ajax({
                url: that.options.url + that.options.loggedUser + "/logout",
                type: "GET",
                // NOTE: This is non-async because we want to serially streamline the logout/login that is triggered
                // by the GPIIStore "refresh" of system level applications when setting preferences.
                async: false,
                /*xhrFields: {
                    withCredentials: true
                },*/
                success: function (data) {
                    that.options.loggedUser = null;
                    that.events.onLogout.fire();
                    fluid.log("GET: " + data);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    fluid.log("GET: Error at logging out user " + that.options.loggedUser + "! Test status: " + textStatus);
                    fluid.log(errorThrown);
                }
            });
        }
    };

})(jQuery, fluid);
{'fraction_non_alphanumeric': 0.11215308579394247, 'fraction_numerical': 0.004435432771511849, 'mean_word_length': 1.6236702127659575, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3846382', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2102, 'n_words': 570}