1 // Copyright (c) 2016-2023 by the citadel.org team
3 // This program is open source software. Use, duplication, or
4 // disclosure is subject to the GNU General Public License v3.
7 // This is where the login screen (modal) is displayed.
8 // It appears in the "ctdl_big_modal" div which is defined in index.html and is used for several different modals.
9 // If you want to change the look of the login dialog, this is where to change it.
10 function display_login_screen(any_message) {
11 document.getElementById("ctdl_big_modal").innerHTML = `
13 <div class="ctdl-modal-header">
14 <span><i class="fa fa-user"></i></span>
15 <span>${any_message}</span>
18 <div class="ctdl-login-screen-grid-container">
19 <div class="ctdl-login-screen-grid-item"><label><b>${_("User name:")}</b></label></div>
20 <div class="ctdl-login-screen-grid-item"><input type="text" id="username" required></div>
21 <div class="ctdl-login-screen-grid-item"><label><b>${_("Password:")}</b></label></div>
22 <div class="ctdl-login-screen-grid-item"><input type="password" id="password" required></div>
23 <div class="ctdl-login-screen-grid-item"></div>
24 <div class="ctdl-login-screen-grid-item">
25 <input type="checkbox" checked="checked">
28 <div class="ctdl-login-screen-grid-item"></div>
29 <div class="ctdl-login-screen-grid-item">
30 <button onClick="javascript:login_button()">${_("Log in")}</button>
31 <button type="button">Cancel</button>
36 document.getElementById("ctdl_big_modal").style.display = "block";
40 // When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session.
41 // When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing.
43 //logout = async() => {
44 //response = await fetch("/ctdl/a/logout");
45 //ctdl_startup(); // let the regular startup code take care of everything else
49 function login_button(username) {
51 document.getElementById("username").value
53 + document.getElementById("password").value
57 var request = new XMLHttpRequest();
58 request.open("POST", "/ctdl/a/login", true);
59 request.onreadystatechange = function() {
60 if (this.readyState === XMLHttpRequest.DONE) {
61 login_result(JSON.parse(this.responseText));
69 // Feed this a JSON output from login_button() or a similar function
70 function login_result(data) {
72 document.getElementById("ctdl_big_modal").style.display = "none";
73 ctdl_startup(); // let the regular startup code take care of everything else
76 display_login_screen(data.message);
81 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
82 function detect_logged_in() {
84 wcauth_decoded = atob(getCookieValue("wcauth"));
85 wcauth_user = wcauth_decoded.split(":")[0];
90 if (wcauth_user.length > 0) {
92 current_user = wcauth_user;
96 current_user = _("Not logged in.");