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 w3-card-4 w3-animate-zoom" style="max-width:600px">
21 <div class="w3-center"><br>
22 <span class="w3-button w3-xlarge w3-transparent w3-display-topright" title="Close Modal">×</span>
23 <span class="w3-circle w3-margin-top"><i class="fa fa-user"></i></span>
26 <div class="w3-container">
27 <div class="w3-section">
28 <span class="w3-center w3-red">${any_message}</span>
30 <div class="w3-section">
31 <label><b>${_("User name:")}</b></label>
32 <input class="w3-input w3-border w3-margin-bottom" type="text" id="username" required>
33 <label><b>${_("Password:")}</b></label>
34 <input class="w3-input w3-border" type="password" id="password" required>
35 <button class="w3-button w3-block w3-blue w3-section w3-padding" onClick="javascript:login_button()">${_("Log in")}</button>
36 <input class="w3-check w3-margin-top" type="checkbox" checked="checked"> Remember me
40 <div class="w3-container w3-border-top w3-padding-16 w3-light-grey">
41 <button type="button" class="w3-button w3-red">Cancel</button>
42 <span class="w3-right w3-padding w3-hide-small">Forgot <a href="#">password?</a></span>
47 document.getElementById("ctdl_big_modal").style.display = "block";
51 // When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session.
52 // When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing.
55 response = await fetch("/ctdl/a/logout");
56 ctdl_startup(); // let the regular startup code take care of everything else
60 function login_button(username) {
62 document.getElementById("username").value
64 + document.getElementById("password").value
68 var request = new XMLHttpRequest();
69 request.open("POST", "/ctdl/a/login", true);
70 request.onreadystatechange = function() {
71 if (this.readyState === XMLHttpRequest.DONE) {
72 login_result(JSON.parse(this.responseText));
80 // Feed this a JSON output from login_button() or a similar function
81 function login_result(data) {
83 document.getElementById("ctdl_big_modal").style.display = "none";
84 ctdl_startup(); // let the regular startup code take care of everything else
87 display_login_screen(data.message);
92 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
93 function detect_logged_in() {
95 wcauth_decoded = atob(getCookieValue("wcauth"));
96 wcauth_user = wcauth_decoded.split(":")[0];
101 if (wcauth_user.length > 0) {
103 current_user = wcauth_user;
107 current_user = _("Not logged in.");