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 = `
13 <div class="ctdl-modal-header">
14 <span><i class="fa fa-user"></i></span>
15 <span>${any_message}</span>
18 <div class="ctdl-modal-main">
19 <label><b>${_("User name:")}</b></label>
20 <input type="text" id="username" required>
22 <label><b>${_("Password:")}</b></label>
23 <input type="password" id="password" required>
25 <input type="checkbox" checked="checked"> Remember me
28 <div class="ctdl-modal-footer">
29 <button onClick="javascript:login_button()">${_("Log in")}</button>
30 <button type="button">Cancel</button>
34 document.getElementById("ctdl_big_modal").style.display = "block";
38 // When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session.
39 // When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing.
42 response = await fetch("/ctdl/a/logout");
43 ctdl_startup(); // let the regular startup code take care of everything else
47 function login_button(username) {
49 document.getElementById("username").value
51 + document.getElementById("password").value
55 var request = new XMLHttpRequest();
56 request.open("POST", "/ctdl/a/login", true);
57 request.onreadystatechange = function() {
58 if (this.readyState === XMLHttpRequest.DONE) {
59 login_result(JSON.parse(this.responseText));
67 // Feed this a JSON output from login_button() or a similar function
68 function login_result(data) {
70 document.getElementById("ctdl_big_modal").style.display = "none";
71 ctdl_startup(); // let the regular startup code take care of everything else
74 display_login_screen(data.message);
79 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
80 function detect_logged_in() {
82 wcauth_decoded = atob(getCookieValue("wcauth"));
83 wcauth_user = wcauth_decoded.split(":")[0];
88 if (wcauth_user.length > 0) {
90 current_user = wcauth_user;
94 current_user = _("Not logged in.");