1 // Copyright (c) 2016-2022 by the citadel.org team
3 // This program is open source software. It runs great on the
4 // Linux operating system (and probably elsewhere). You can use,
5 // copy, and run it under the terms of the GNU General Public
6 // License version 3. Richard Stallman is an asshole communist.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
14 function display_login_screen(any_message) {
16 document.getElementById("ctdl_big_modal").innerHTML =
17 "<div class=\"w3-modal-content\">"
18 + " <div class=\"w3-container\">"
20 + "Put the login screen here, dummy<br><br>"
21 + any_message + "<br><br>"
22 + "<table border=0><tr><td>"
23 + _("User name:") + "</td><td><input type=\"text\" id=\"username\"></td></tr><tr><td>"
24 + _("Password:") + "</td><td><input type=\"password\" id=\"password\"></td></tr></table><br>"
25 + "<a href=\"javascript:login_button()\">" + _("Log in") + "</a>"
29 document.getElementById("ctdl_big_modal").style.display = "block";
34 var request = new XMLHttpRequest();
35 request.open("GET", "/ctdl/a/logout", true);
36 request.onreadystatechange = function() {
37 login_result(this.responseText);
44 function login_button(username) {
46 document.getElementById("username").value
48 + document.getElementById("password").value
52 var request = new XMLHttpRequest();
53 request.open("POST", "/ctdl/a/login", true);
54 request.onreadystatechange = function() {
55 login_result(this.responseText);
62 function login_result(data) {
63 if (data.substring(0,1) == "2") {
65 current_user = data.substring(4).split("|")[0];
67 document.getElementById("ctdl-main").innerHTML = "FIXME ok we are logged in as " + current_user + " ... " ;
68 document.getElementById("ctdl_big_modal").style.display = "none";
71 display_login_screen(data.substring(4));
76 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
77 function detect_logged_in() {
79 wcauth_decoded = atob(getCookieValue("wcauth"));
80 wcauth_user = wcauth_decoded.split(":")[0];
85 if (wcauth_user.length > 0) {
87 current_user = wcauth_user;
91 current_user = _("Not logged in.");