<commit_before>/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
 */

var cockpit = cockpit || { };

(function(cockpit, $) {

$(function() {
    $(".cockpit-deauthorize-item a").on("click", function(ev) {
        var req = new XMLHttpRequest();
        var loc = window.location.protocol + "//" + window.location.host + "/deauthorize";
        req.open("POST", loc, true);
        req.onreadystatechange = function (event) {
            if (req.readyState == 4) {
                $(".cockpit-deauthorize-item").addClass("disabled");
                $(".cockpit-deauthorize-item a").off("click");

                /* TODO: We need a better indicator for deauthorized state */
                $(".cockpit-deauthorize-status").text("deauthorized");
            }
        };
        req.send();
        ev.preventDefault();
    });

    var is_root = cockpit.connection_config.user == "root";
    $('#cockpit-go-account').toggle(!is_root);
    $('#cockpit-change-passwd').toggle(is_root);
});

}(cockpit, jQuery));

function cockpit_logout (reason)
{
    var req = new XMLHttpRequest();
    var loc = window.location.protocol + "//" + window.location.host + "/logout";
    req.open("POST", loc, true);
    req.onreadystatechange = function (event) {
	if (req.readyState == 4) {
            cockpit.set_watched_client(null);
            window.location.reload(true);
        }
    };
    req.send();
}

function cockpit_go_login_account ()
{
    cockpit_go_server ("localhost",
                       [ { page: "accounts" },
                         { page: "account", id: cockpit.connection_config.user }
                       ]);
}<commit_msg>shell: Use the logout command to logout and deauthorize<commit_after>/*
 * This file is part of Cockpit.
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * Cockpit is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Cockpit is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
 */

var cockpit = cockpit || { };

(function(cockpit, $) {

$(function() {
    $(".cockpit-deauthorize-item a").on("click", function(ev) {
        /* Ensure Channel.transport is not null */
        var channel = new Channel({ "payload": "null" });
        Channel.transport.logout(false);
        channel.close();
        $(".cockpit-deauthorize-item").addClass("disabled");
        $(".cockpit-deauthorize-item a").off("click");

        /* TODO: We need a better indicator for deauthorized state */
        $(".cockpit-deauthorize-status").text("deauthorized");
        ev.preventDefault();
    });

    var is_root = cockpit.connection_config.user == "root";
    $('#cockpit-go-account').toggle(!is_root);
    $('#cockpit-change-passwd').toggle(is_root);
});

}(cockpit, jQuery));

function cockpit_logout (reason)
{
    var channel = new Channel({ "payload": "null" });
    $(channel).on("close", function() {
        window.location.reload(true);
    });
    cockpit.set_watched_client(null);
    Channel.transport.logout(true);
}

function cockpit_go_login_account ()
{
    cockpit_go_server ("localhost",
                       [ { page: "accounts" },
                         { page: "account", id: cockpit.connection_config.user }
                       ]);
}
{'fraction_non_alphanumeric': 0.1344269765322397, 'fraction_numerical': 0.003189792663476874, 'mean_word_length': 2.7682403433476397, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2861436', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1218, 'n_words': 382}