checks the server cookie instead of clumsily attempting a command.
This works synchronously so it can be combined with other commands
without creating a race condition. Also moved the login screen to
a modal.
--len;
}
buf[len] = 0;
- // syslog(LOG_DEBUG, "\033[33m[ %s\033[0m", buf);
+ syslog(LOG_DEBUG, "\033[32m[ %s\033[0m", buf);
return (len);
}
++len;
}
- // syslog(LOG_DEBUG, "\033[33m[ %s\033[0m", buf);
+ syslog(LOG_DEBUG, "\033[32m[ %s\033[0m", buf);
return (len);
}
#endif
// Output the results back to the client.
- syslog(LOG_DEBUG, "> %03d %s", h.response_code, h.response_string);
+ syslog(LOG_DEBUG, "\033[33m\033[1m> %03d %s\033[0m", h.response_code, h.response_string);
client_printf(ch, "HTTP/1.1 %03d %s\r\n", h.response_code, h.response_string);
client_printf(ch, "Connection: close\r\n");
client_printf(ch, "Content-Length: %ld\r\n", h.response_body_length);
<!-- Modal dialog (when needed) -->
<div id="ctdl_big_modal" class="w3-modal" style="display:none; z-index:5">
- <div class="w3-modal-content">
- <div id="ctdl_big_modal_content" class="w3-container">
- <p>Loading...</p>
- </div>
- </div>
+LOADING
</div>
<!-- Top container -->
-//
-// Copyright (c) 2016-2020 by the citadel.org team
+// Copyright (c) 2016-2022 by the citadel.org team
//
// This program is open source software. It runs great on the
// Linux operating system (and probably elsewhere). You can use,
// GNU General Public License for more details.
-function display_login_screen(any_message)
-{
- document.getElementById("ctdl-main").innerHTML =
- "<center><br><br>Put the login screen here, dummary<br><br>" +
- any_message + "<br><br>" +
- "<table border=0><tr><td>" +
- _("User name:") + "</td><td><input type=\"text\" id=\"username\"></td></tr><tr><td>" +
- _("Password:") + "</td><td><input type=\"password\" id=\"password\"></td></tr></table><br>" +
- "<a href=\"javascript:login_button()\">" + _("Log in") + "</a></center>"
- ;
+function display_login_screen(any_message) {
+
+ document.getElementById("ctdl_big_modal").innerHTML =
+ "<div class=\"w3-modal-content\">"
+ + " <div class=\"w3-container\">"
+
+ + "Put the login screen here, dummy<br><br>"
+ + any_message + "<br><br>"
+ + "<table border=0><tr><td>"
+ + _("User name:") + "</td><td><input type=\"text\" id=\"username\"></td></tr><tr><td>"
+ + _("Password:") + "</td><td><input type=\"password\" id=\"password\"></td></tr></table><br>"
+ + "<a href=\"javascript:login_button()\">" + _("Log in") + "</a>"
- update_banner();
+ + " </div>"
+ + "</div>";
+ document.getElementById("ctdl_big_modal").style.display = "block";
}
-function logout()
-{
+function logout() {
var request = new XMLHttpRequest();
request.open("GET", "/ctdl/a/logout", true);
request.onreadystatechange = function() {
}
-function login_button(username)
-{
+function login_button(username) {
parms =
document.getElementById("username").value
+ "|"
}
-function login_result(data)
-{
+function login_result(data) {
if (data.substring(0,1) == "2") {
logged_in = 1;
current_user = data.substring(4).split("|")[0];
update_banner();
document.getElementById("ctdl-main").innerHTML = "FIXME ok we are logged in as " + current_user + " ... " ;
+ document.getElementById("ctdl_big_modal").style.display = "none";
}
else {
display_login_screen(data.substring(4));
// Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
-//
-function detect_logged_in()
-{
- var request = new XMLHttpRequest();
- request.open("GET", "/ctdl/a/whoami", true);
- request.onreadystatechange = function() {
- detect_logged_in_2(this.responseText);
- };
- request.send();
- request = null;
-}
-function detect_logged_in_2(data)
-{
- if (data.length > 0) {
+function detect_logged_in() {
+ try {
+ wcauth_decoded = atob(getCookieValue("wcauth"));
+ wcauth_user = wcauth_decoded.split(":")[0];
+ }
+ catch(err) {
+ wcauth_user = "";
+ }
+ if (wcauth_user.length > 0) {
logged_in = 1;
- current_user = data;
+ current_user = wcauth_user;
}
else {
logged_in = 0;
-//
// Copyright (c) 2016-2020 by the citadel.org team
//
// This program is open source software. It runs great on the
update_banner();
- // for now, show a room list in the main div
- gotoroom("_BASEROOM_");
- display_room_list();
+ // What do we do upon landing?
+
+ if ( (serv_info.serv_supports_guest) || (logged_in) ) { // If the Lobby is visible,
+ gotoroom("_BASEROOM_"); // go there.
+ display_room_list();
+ }
+ else { // Otherwise,
+ display_login_screen("logged in users only. sheeeeeeeeeit."); // display the login modal.
+ }
}
else {
document.getElementById("ctdl-main").innerHTML =
// goto room
-//
function gotoroom(roomname) {
fetch_room = async() => {
response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
- data = await(response.json());
if (response.ok) {
+ data = await(response.json());
current_room = data.name;
new_messages = data.new_messages;
total_messages = data.total_messages;
// Activate the "Loading..." modal
function activate_loading_modal() {
- document.getElementById("ctdl_big_modal_content").innerHTML =
- "<i class=\"fas fa-spinner fa-spin\"></i> "
- + _("Loading messages from server, please wait");
+ document.getElementById("ctdl_big_modal").innerHTML =
+ "<div class=\"w3-modal-content\">"
+ + " <div class=\"w3-container\">"
+
+ + "<i class=\"fas fa-spinner fa-spin\"></i> "
+ + _("Loading messages from server, please wait")
+
+ + " </div>"
+ + "</div>";
document.getElementById("ctdl_big_modal").style.display = "block";
}
return time;
}
+
+
+// Get the value of a cookie from the HTTP session
+// Shamelessly swiped from https://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript
+const getCookieValue = (name) => (
+ document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || ''
+)
+
+
return rc == 2;
}
+
int Conditional_LISTSUB_EXECUTE_CONFIRMSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP) {
if (strcmp(bstr("cmd"), "confirm_subscribe")) {
return 0;