1 // Copyright (c) 2016-2022 by the citadel.org team
3 // This program is open source software. Use, duplication, or
4 // disclosure are 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 = `
12 <div class="w3-modal-content w3-card-4 w3-animate-zoom" style="max-width:600px">
14 <div class="w3-center"><br>
15 <span class="w3-button w3-xlarge w3-transparent w3-display-topright" title="Close Modal">×</span>
16 <span class="w3-circle w3-margin-top"><i class="fa fa-user"></i></span>
19 <div class="w3-container">
20 <div class="w3-section">
21 <span class="w3-center w3-red">${any_message}</span>
23 <div class="w3-section">
24 <label><b>${_("User name:")}</b></label>
25 <input class="w3-input w3-border w3-margin-bottom" type="text" id="username" required>
26 <label><b>${_("Password:")}</b></label>
27 <input class="w3-input w3-border" type="password" id="password" required>
28 <button class="w3-button w3-block w3-blue w3-section w3-padding" onClick="javascript:login_button()">${_("Log in")}</button>
29 <input class="w3-check w3-margin-top" type="checkbox" checked="checked"> Remember me
33 <div class="w3-container w3-border-top w3-padding-16 w3-light-grey">
34 <button type="button" class="w3-button w3-red">Cancel</button>
35 <span class="w3-right w3-padding w3-hide-small">Forgot <a href="#">password?</a></span>
40 document.getElementById("ctdl_big_modal").style.display = "block";
44 // When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session.
45 // When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing.
48 response = await fetch("/ctdl/a/logout");
49 ctdl_startup(); // let the regular startup code take care of everything else
53 function login_button(username) {
55 document.getElementById("username").value
57 + document.getElementById("password").value
61 var request = new XMLHttpRequest();
62 request.open("POST", "/ctdl/a/login", true);
63 request.onreadystatechange = function() {
64 if (this.readyState === XMLHttpRequest.DONE) {
65 login_result(JSON.parse(this.responseText));
73 // Feed this a JSON output from login_button() or a similar function
74 function login_result(data) {
76 document.getElementById("ctdl_big_modal").style.display = "none";
77 ctdl_startup(); // let the regular startup code take care of everything else
80 display_login_screen(data.message);
85 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
86 function detect_logged_in() {
88 wcauth_decoded = atob(getCookieValue("wcauth"));
89 wcauth_user = wcauth_decoded.split(":")[0];
94 if (wcauth_user.length > 0) {
96 current_user = wcauth_user;
100 current_user = _("Not logged in.");