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 // This is where the login screen (modal) is displayed.
15 // It appears in the "ctdl_big_modal" div which is defined in index.html and is used for several different modals.
16 // If you want to change the look of the login dialog, this is where to change it.
17 function display_login_screen(any_message) {
18 document.getElementById("ctdl_big_modal").innerHTML =
19 "<div class=\"w3-modal-content\">"
20 + "<div class=\"w3-panel w3-border w3-border-blue w3-topbar w3-bottombar w3-leftbar w3-rightbar\"><center>"
21 + "<p>FIXME put a login banner here, dummy</p>"
22 + "<p>" + any_message + "</p>"
23 + "<table border=0><tr><td>"
24 + _("User name:") + "</td><td><input type=\"text\" id=\"username\"></td></tr><tr><td>"
25 + _("Password:") + "</td><td><input type=\"password\" id=\"password\"></td></tr></table><br>"
27 + "<button class=\"w3-button w3-blue\" onClick=\"javascript:login_button()\">" + _("Log in") + "</button>"
31 document.getElementById("ctdl_big_modal").style.display = "block";
35 // When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session.
36 // When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing.
40 response = await fetch("/ctdl/a/logout");
45 function login_button(username) {
47 document.getElementById("username").value
49 + document.getElementById("password").value
53 var request = new XMLHttpRequest();
54 request.open("POST", "/ctdl/a/login", true);
55 request.onreadystatechange = function() {
56 login_result(this.responseText);
63 function login_result(data) {
64 if (data.substring(0,1) == "2") {
66 current_user = data.substring(4).split("|")[0];
68 document.getElementById("ctdl-main").innerHTML = "FIXME ok we are logged in as " + current_user + " ... " ;
69 document.getElementById("ctdl_big_modal").style.display = "none";
72 display_login_screen(data.substring(4));
77 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
78 function detect_logged_in() {
80 wcauth_decoded = atob(getCookieValue("wcauth"));
81 wcauth_user = wcauth_decoded.split(":")[0];
86 if (wcauth_user.length > 0) {
88 current_user = wcauth_user;
92 current_user = _("Not logged in.");