fix toggleRecovery text
This commit is contained in:
733
js/authModals.js
733
js/authModals.js
@@ -55,12 +55,23 @@ export function openTOTPLoginModal() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Toggle between TOTP and Recovery
|
// Toggle between TOTP and Recovery
|
||||||
document.getElementById("toggleRecovery").addEventListener("click", e => {
|
document.getElementById("toggleRecovery").addEventListener("click", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
document.getElementById("totpSection").style.display =
|
const totpSection = document.getElementById("totpSection");
|
||||||
document.getElementById("recoverySection").style.display === "none" ? "none" : "block";
|
const recoverySection = document.getElementById("recoverySection");
|
||||||
document.getElementById("recoverySection").style.display =
|
const toggleLink = this;
|
||||||
document.getElementById("recoverySection").style.display === "none" ? "block" : "none";
|
|
||||||
|
if (recoverySection.style.display === "none") {
|
||||||
|
// Switch to recovery
|
||||||
|
totpSection.style.display = "none";
|
||||||
|
recoverySection.style.display = "block";
|
||||||
|
toggleLink.textContent = "Use TOTP Code instead";
|
||||||
|
} else {
|
||||||
|
// Switch back to TOTP
|
||||||
|
recoverySection.style.display = "none";
|
||||||
|
totpSection.style.display = "block";
|
||||||
|
toggleLink.textContent = "Use Recovery Code instead";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Recovery submission
|
// Recovery submission
|
||||||
@@ -79,18 +90,18 @@ export function openTOTPLoginModal() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({ recovery_code: recoveryCode })
|
body: JSON.stringify({ recovery_code: recoveryCode })
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if (json.status === "ok") {
|
if (json.status === "ok") {
|
||||||
// recovery succeeded → finalize login
|
// recovery succeeded → finalize login
|
||||||
window.location.href = "index.html";
|
window.location.href = "index.html";
|
||||||
} else {
|
} else {
|
||||||
showToast(json.message || "Recovery code verification failed");
|
showToast(json.message || "Recovery code verification failed");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
showToast("Error verifying recovery code.");
|
showToast("Error verifying recovery code.");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TOTP submission
|
// TOTP submission
|
||||||
@@ -108,23 +119,23 @@ export function openTOTPLoginModal() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({ totp_code: code })
|
body: JSON.stringify({ totp_code: code })
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if (json.status === "ok") {
|
if (json.status === "ok") {
|
||||||
window.location.href = "index.html";
|
window.location.href = "index.html";
|
||||||
} else {
|
} else {
|
||||||
showToast(json.message || "TOTP verification failed");
|
showToast(json.message || "TOTP verification failed");
|
||||||
|
this.value = "";
|
||||||
|
totpLoginModal.style.display = "flex";
|
||||||
|
totpInput.focus();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showToast("TOTP verification failed");
|
||||||
this.value = "";
|
this.value = "";
|
||||||
totpLoginModal.style.display = "flex";
|
totpLoginModal.style.display = "flex";
|
||||||
totpInput.focus();
|
totpInput.focus();
|
||||||
}
|
});
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
showToast("TOTP verification failed");
|
|
||||||
this.value = "";
|
|
||||||
totpLoginModal.style.display = "flex";
|
|
||||||
totpInput.focus();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -158,9 +169,9 @@ export function openUserPanel() {
|
|||||||
transition: none;
|
transition: none;
|
||||||
`;
|
`;
|
||||||
if (!userPanelModal) {
|
if (!userPanelModal) {
|
||||||
userPanelModal = document.createElement("div");
|
userPanelModal = document.createElement("div");
|
||||||
userPanelModal.id = "userPanelModal";
|
userPanelModal.id = "userPanelModal";
|
||||||
userPanelModal.style.cssText = `
|
userPanelModal.style.cssText = `
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -172,7 +183,7 @@ export function openUserPanel() {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 3000;
|
z-index: 3000;
|
||||||
`;
|
`;
|
||||||
userPanelModal.innerHTML = `
|
userPanelModal.innerHTML = `
|
||||||
<div class="modal-content" style="${modalContentStyles}">
|
<div class="modal-content" style="${modalContentStyles}">
|
||||||
<span id="closeUserPanel" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 24px;">×</span>
|
<span id="closeUserPanel" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 24px;">×</span>
|
||||||
<h3>User Panel (${username})</h3>
|
<h3>User Panel (${username})</h3>
|
||||||
@@ -186,43 +197,43 @@ export function openUserPanel() {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
document.body.appendChild(userPanelModal);
|
document.body.appendChild(userPanelModal);
|
||||||
document.getElementById("closeUserPanel").addEventListener("click", () => {
|
document.getElementById("closeUserPanel").addEventListener("click", () => {
|
||||||
userPanelModal.style.display = "none";
|
userPanelModal.style.display = "none";
|
||||||
});
|
});
|
||||||
document.getElementById("openChangePasswordModalBtn").addEventListener("click", () => {
|
document.getElementById("openChangePasswordModalBtn").addEventListener("click", () => {
|
||||||
document.getElementById("changePasswordModal").style.display = "block";
|
document.getElementById("changePasswordModal").style.display = "block";
|
||||||
});
|
});
|
||||||
const totpCheckbox = document.getElementById("userTOTPEnabled");
|
const totpCheckbox = document.getElementById("userTOTPEnabled");
|
||||||
totpCheckbox.checked = localStorage.getItem("userTOTPEnabled") === "true";
|
totpCheckbox.checked = localStorage.getItem("userTOTPEnabled") === "true";
|
||||||
totpCheckbox.addEventListener("change", function () {
|
totpCheckbox.addEventListener("change", function () {
|
||||||
localStorage.setItem("userTOTPEnabled", this.checked ? "true" : "false");
|
localStorage.setItem("userTOTPEnabled", this.checked ? "true" : "false");
|
||||||
const enabled = this.checked;
|
const enabled = this.checked;
|
||||||
fetch("updateUserPanel.php", {
|
fetch("updateUserPanel.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-CSRF-Token": window.csrfToken
|
"X-CSRF-Token": window.csrfToken
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ totp_enabled: enabled })
|
body: JSON.stringify({ totp_enabled: enabled })
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
showToast("Error updating TOTP setting: " + result.error);
|
showToast("Error updating TOTP setting: " + result.error);
|
||||||
} else if (enabled) {
|
} else if (enabled) {
|
||||||
openTOTPModal();
|
openTOTPModal();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => { showToast("Error updating TOTP setting."); });
|
.catch(() => { showToast("Error updating TOTP setting."); });
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
userPanelModal.style.backgroundColor = overlayBackground;
|
userPanelModal.style.backgroundColor = overlayBackground;
|
||||||
const modalContent = userPanelModal.querySelector(".modal-content");
|
const modalContent = userPanelModal.querySelector(".modal-content");
|
||||||
modalContent.style.background = isDarkMode ? "#2c2c2c" : "#fff";
|
modalContent.style.background = isDarkMode ? "#2c2c2c" : "#fff";
|
||||||
modalContent.style.color = isDarkMode ? "#e0e0e0" : "#000";
|
modalContent.style.color = isDarkMode ? "#e0e0e0" : "#000";
|
||||||
modalContent.style.border = isDarkMode ? "1px solid #444" : "1px solid #ccc";
|
modalContent.style.border = isDarkMode ? "1px solid #444" : "1px solid #ccc";
|
||||||
}
|
}
|
||||||
userPanelModal.style.display = "flex";
|
userPanelModal.style.display = "flex";
|
||||||
}
|
}
|
||||||
@@ -251,7 +262,7 @@ function showRecoveryCodeModal(recoveryCode) {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
document.body.appendChild(recoveryModal);
|
document.body.appendChild(recoveryModal);
|
||||||
|
|
||||||
document.getElementById("closeRecoveryModal").addEventListener("click", () => {
|
document.getElementById("closeRecoveryModal").addEventListener("click", () => {
|
||||||
recoveryModal.remove();
|
recoveryModal.remove();
|
||||||
});
|
});
|
||||||
@@ -299,11 +310,11 @@ export function openTOTPModal() {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
document.body.appendChild(totpModal);
|
document.body.appendChild(totpModal);
|
||||||
|
|
||||||
document.getElementById("closeTOTPModal").addEventListener("click", () => {
|
document.getElementById("closeTOTPModal").addEventListener("click", () => {
|
||||||
closeTOTPModal(true);
|
closeTOTPModal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("confirmTOTPBtn").addEventListener("click", function () {
|
document.getElementById("confirmTOTPBtn").addEventListener("click", function () {
|
||||||
const code = document.getElementById("totpConfirmInput").value.trim();
|
const code = document.getElementById("totpConfirmInput").value.trim();
|
||||||
if (code.length !== 6) {
|
if (code.length !== 6) {
|
||||||
@@ -313,41 +324,41 @@ export function openTOTPModal() {
|
|||||||
fetch("totp_verify.php", {
|
fetch("totp_verify.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-CSRF-Token": window.csrfToken
|
"X-CSRF-Token": window.csrfToken
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ totp_code: code })
|
body: JSON.stringify({ totp_code: code })
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.status === 'ok') {
|
if (result.status === 'ok') {
|
||||||
showToast("TOTP successfully enabled.");
|
showToast("TOTP successfully enabled.");
|
||||||
// After successful TOTP verification, fetch the recovery code
|
// After successful TOTP verification, fetch the recovery code
|
||||||
fetch("totp_saveCode.php", {
|
fetch("totp_saveCode.php", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-CSRF-Token": window.csrfToken
|
"X-CSRF-Token": window.csrfToken
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.status === 'ok' && data.recoveryCode) {
|
if (data.status === 'ok' && data.recoveryCode) {
|
||||||
// Show the recovery code in a secure modal
|
// Show the recovery code in a secure modal
|
||||||
showRecoveryCodeModal(data.recoveryCode);
|
showRecoveryCodeModal(data.recoveryCode);
|
||||||
} else {
|
} else {
|
||||||
showToast("Error generating recovery code: " + (data.message || "Unknown error."));
|
showToast("Error generating recovery code: " + (data.message || "Unknown error."));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => { showToast("Error generating recovery code."); });
|
.catch(() => { showToast("Error generating recovery code."); });
|
||||||
closeTOTPModal(false);
|
closeTOTPModal(false);
|
||||||
} else {
|
} else {
|
||||||
showToast("TOTP verification failed: " + (result.message || "Invalid code."));
|
showToast("TOTP verification failed: " + (result.message || "Invalid code."));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => { showToast("Error verifying TOTP code."); });
|
.catch(() => { showToast("Error verifying TOTP code."); });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Focus the input and attach enter key listener
|
// Focus the input and attach enter key listener
|
||||||
@@ -366,7 +377,7 @@ export function openTOTPModal() {
|
|||||||
const modalContent = totpModal.querySelector(".modal-content");
|
const modalContent = totpModal.querySelector(".modal-content");
|
||||||
modalContent.style.background = isDarkMode ? "#2c2c2c" : "#fff";
|
modalContent.style.background = isDarkMode ? "#2c2c2c" : "#fff";
|
||||||
modalContent.style.color = isDarkMode ? "#e0e0e0" : "#000";
|
modalContent.style.color = isDarkMode ? "#e0e0e0" : "#000";
|
||||||
|
|
||||||
// Focus the input and attach enter key listener
|
// Focus the input and attach enter key listener
|
||||||
const totpConfirmInput = document.getElementById("totpConfirmInput");
|
const totpConfirmInput = document.getElementById("totpConfirmInput");
|
||||||
if (totpConfirmInput) {
|
if (totpConfirmInput) {
|
||||||
@@ -382,44 +393,44 @@ export function openTOTPModal() {
|
|||||||
|
|
||||||
// Updated closeTOTPModal function with a disable parameter
|
// Updated closeTOTPModal function with a disable parameter
|
||||||
export function closeTOTPModal(disable = true) {
|
export function closeTOTPModal(disable = true) {
|
||||||
const totpModal = document.getElementById("totpModal");
|
const totpModal = document.getElementById("totpModal");
|
||||||
if (totpModal) totpModal.style.display = "none";
|
if (totpModal) totpModal.style.display = "none";
|
||||||
|
|
||||||
if (disable) {
|
if (disable) {
|
||||||
// Uncheck the Enable TOTP checkbox
|
// Uncheck the Enable TOTP checkbox
|
||||||
const totpCheckbox = document.getElementById("userTOTPEnabled");
|
const totpCheckbox = document.getElementById("userTOTPEnabled");
|
||||||
if (totpCheckbox) {
|
if (totpCheckbox) {
|
||||||
totpCheckbox.checked = false;
|
totpCheckbox.checked = false;
|
||||||
localStorage.setItem("userTOTPEnabled", "false");
|
localStorage.setItem("userTOTPEnabled", "false");
|
||||||
|
}
|
||||||
|
// Call endpoint to remove the TOTP secret from the user's record
|
||||||
|
fetch("totp_disable.php", {
|
||||||
|
method: "POST",
|
||||||
|
credentials: "include",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-CSRF-Token": window.csrfToken
|
||||||
}
|
}
|
||||||
// Call endpoint to remove the TOTP secret from the user's record
|
})
|
||||||
fetch("totp_disable.php", {
|
.then(r => r.json())
|
||||||
method: "POST",
|
.then(result => {
|
||||||
credentials: "include",
|
if (!result.success) {
|
||||||
headers: {
|
showToast("Error disabling TOTP setting: " + result.error);
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-CSRF-Token": window.csrfToken
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.catch(() => { showToast("Error disabling TOTP setting."); });
|
||||||
.then(result => {
|
|
||||||
if (!result.success) {
|
|
||||||
showToast("Error disabling TOTP setting: " + result.error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => { showToast("Error disabling TOTP setting."); });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function openAdminPanel() {
|
export function openAdminPanel() {
|
||||||
fetch("getConfig.php", { credentials: "include" })
|
fetch("getConfig.php", { credentials: "include" })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(config => {
|
.then(config => {
|
||||||
if (config.oidc) Object.assign(window.currentOIDCConfig, config.oidc);
|
if (config.oidc) Object.assign(window.currentOIDCConfig, config.oidc);
|
||||||
if (config.globalOtpauthUrl) window.currentOIDCConfig.globalOtpauthUrl = config.globalOtpauthUrl;
|
if (config.globalOtpauthUrl) window.currentOIDCConfig.globalOtpauthUrl = config.globalOtpauthUrl;
|
||||||
const isDarkMode = document.body.classList.contains("dark-mode");
|
const isDarkMode = document.body.classList.contains("dark-mode");
|
||||||
const overlayBackground = isDarkMode ? "rgba(0,0,0,0.7)" : "rgba(0,0,0,0.3)";
|
const overlayBackground = isDarkMode ? "rgba(0,0,0,0.7)" : "rgba(0,0,0,0.3)";
|
||||||
const modalContentStyles = `
|
const modalContentStyles = `
|
||||||
background: ${isDarkMode ? "#2c2c2c" : "#fff"};
|
background: ${isDarkMode ? "#2c2c2c" : "#fff"};
|
||||||
color: ${isDarkMode ? "#e0e0e0" : "#000"};
|
color: ${isDarkMode ? "#e0e0e0" : "#000"};
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
@@ -431,12 +442,12 @@ export function openAdminPanel() {
|
|||||||
max-height: 90vh;
|
max-height: 90vh;
|
||||||
border: ${isDarkMode ? "1px solid #444" : "1px solid #ccc"};
|
border: ${isDarkMode ? "1px solid #444" : "1px solid #ccc"};
|
||||||
`;
|
`;
|
||||||
let adminModal = document.getElementById("adminPanelModal");
|
let adminModal = document.getElementById("adminPanelModal");
|
||||||
|
|
||||||
if (!adminModal) {
|
if (!adminModal) {
|
||||||
adminModal = document.createElement("div");
|
adminModal = document.createElement("div");
|
||||||
adminModal.id = "adminPanelModal";
|
adminModal.id = "adminPanelModal";
|
||||||
adminModal.style.cssText = `
|
adminModal.style.cssText = `
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -448,8 +459,8 @@ export function openAdminPanel() {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 3000;
|
z-index: 3000;
|
||||||
`;
|
`;
|
||||||
// Added a version number next to "Admin Panel"
|
// Added a version number next to "Admin Panel"
|
||||||
adminModal.innerHTML = `
|
adminModal.innerHTML = `
|
||||||
<div class="modal-content" style="${modalContentStyles}">
|
<div class="modal-content" style="${modalContentStyles}">
|
||||||
<span id="closeAdminPanel" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 24px;">×</span>
|
<span id="closeAdminPanel" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 24px;">×</span>
|
||||||
<h3>
|
<h3>
|
||||||
@@ -512,151 +523,151 @@ export function openAdminPanel() {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
document.body.appendChild(adminModal);
|
document.body.appendChild(adminModal);
|
||||||
|
|
||||||
document.getElementById("closeAdminPanel").addEventListener("click", closeAdminPanel);
|
document.getElementById("closeAdminPanel").addEventListener("click", closeAdminPanel);
|
||||||
adminModal.addEventListener("click", (e) => {
|
adminModal.addEventListener("click", (e) => {
|
||||||
if (e.target === adminModal) closeAdminPanel();
|
if (e.target === adminModal) closeAdminPanel();
|
||||||
});
|
|
||||||
document.getElementById("cancelAdminSettings").addEventListener("click", closeAdminPanel);
|
|
||||||
document.getElementById("adminOpenAddUser").addEventListener("click", () => {
|
|
||||||
toggleVisibility("addUserModal", true);
|
|
||||||
document.getElementById("newUsername").focus();
|
|
||||||
});
|
|
||||||
document.getElementById("adminOpenRemoveUser").addEventListener("click", () => {
|
|
||||||
if (typeof window.loadUserList === "function") {
|
|
||||||
window.loadUserList();
|
|
||||||
}
|
|
||||||
toggleVisibility("removeUserModal", true);
|
|
||||||
});
|
|
||||||
// New event binding for the User Permissions button:
|
|
||||||
document.getElementById("adminOpenUserPermissions").addEventListener("click", () => {
|
|
||||||
openUserPermissionsModal();
|
|
||||||
});
|
|
||||||
document.getElementById("saveAdminSettings").addEventListener("click", () => {
|
|
||||||
const disableFormLoginCheckbox = document.getElementById("disableFormLogin");
|
|
||||||
const disableBasicAuthCheckbox = document.getElementById("disableBasicAuth");
|
|
||||||
const disableOIDCLoginCheckbox = document.getElementById("disableOIDCLogin");
|
|
||||||
const totalDisabled = [disableFormLoginCheckbox, disableBasicAuthCheckbox, disableOIDCLoginCheckbox].filter(cb => cb.checked).length;
|
|
||||||
if (totalDisabled === 3) {
|
|
||||||
showToast("At least one login method must remain enabled.");
|
|
||||||
disableOIDCLoginCheckbox.checked = false;
|
|
||||||
localStorage.setItem("disableOIDCLogin", "false");
|
|
||||||
if (typeof window.updateLoginOptionsUI === "function") {
|
|
||||||
window.updateLoginOptionsUI({
|
|
||||||
disableFormLogin: disableFormLoginCheckbox.checked,
|
|
||||||
disableBasicAuth: disableBasicAuthCheckbox.checked,
|
|
||||||
disableOIDCLogin: disableOIDCLoginCheckbox.checked
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newOIDCConfig = {
|
|
||||||
providerUrl: document.getElementById("oidcProviderUrl").value.trim(),
|
|
||||||
clientId: document.getElementById("oidcClientId").value.trim(),
|
|
||||||
clientSecret: document.getElementById("oidcClientSecret").value.trim(),
|
|
||||||
redirectUri: document.getElementById("oidcRedirectUri").value.trim()
|
|
||||||
};
|
|
||||||
const disableFormLogin = disableFormLoginCheckbox.checked;
|
|
||||||
const disableBasicAuth = disableBasicAuthCheckbox.checked;
|
|
||||||
const disableOIDCLogin = disableOIDCLoginCheckbox.checked;
|
|
||||||
const globalOtpauthUrl = document.getElementById("globalOtpauthUrl").value.trim();
|
|
||||||
sendRequest("updateConfig.php", "POST", {
|
|
||||||
oidc: newOIDCConfig,
|
|
||||||
disableFormLogin,
|
|
||||||
disableBasicAuth,
|
|
||||||
disableOIDCLogin,
|
|
||||||
globalOtpauthUrl
|
|
||||||
}, { "X-CSRF-Token": window.csrfToken })
|
|
||||||
.then(response => {
|
|
||||||
if (response.success) {
|
|
||||||
showToast("Settings updated successfully.");
|
|
||||||
localStorage.setItem("disableFormLogin", disableFormLogin);
|
|
||||||
localStorage.setItem("disableBasicAuth", disableBasicAuth);
|
|
||||||
localStorage.setItem("disableOIDCLogin", disableOIDCLogin);
|
|
||||||
if (typeof window.updateLoginOptionsUI === "function") {
|
|
||||||
window.updateLoginOptionsUI({ disableFormLogin, disableBasicAuth, disableOIDCLogin });
|
|
||||||
}
|
|
||||||
closeAdminPanel();
|
|
||||||
} else {
|
|
||||||
showToast("Error updating settings: " + (response.error || "Unknown error"));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => { });
|
|
||||||
});
|
|
||||||
const disableFormLoginCheckbox = document.getElementById("disableFormLogin");
|
|
||||||
const disableBasicAuthCheckbox = document.getElementById("disableBasicAuth");
|
|
||||||
const disableOIDCLoginCheckbox = document.getElementById("disableOIDCLogin");
|
|
||||||
function enforceLoginOptionConstraint(changedCheckbox) {
|
|
||||||
const totalDisabled = [disableFormLoginCheckbox, disableBasicAuthCheckbox, disableOIDCLoginCheckbox].filter(cb => cb.checked).length;
|
|
||||||
if (changedCheckbox.checked && totalDisabled === 3) {
|
|
||||||
showToast("At least one login method must remain enabled.");
|
|
||||||
changedCheckbox.checked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
disableFormLoginCheckbox.addEventListener("change", function () { enforceLoginOptionConstraint(this); });
|
|
||||||
disableBasicAuthCheckbox.addEventListener("change", function () { enforceLoginOptionConstraint(this); });
|
|
||||||
disableOIDCLoginCheckbox.addEventListener("change", function () { enforceLoginOptionConstraint(this); });
|
|
||||||
|
|
||||||
document.getElementById("disableFormLogin").checked = config.loginOptions.disableFormLogin === true;
|
|
||||||
document.getElementById("disableBasicAuth").checked = config.loginOptions.disableBasicAuth === true;
|
|
||||||
document.getElementById("disableOIDCLogin").checked = config.loginOptions.disableOIDCLogin === true;
|
|
||||||
} else {
|
|
||||||
adminModal.style.backgroundColor = overlayBackground;
|
|
||||||
const modalContent = adminModal.querySelector(".modal-content");
|
|
||||||
if (modalContent) {
|
|
||||||
modalContent.style.background = isDarkMode ? "#2c2c2c" : "#fff";
|
|
||||||
modalContent.style.color = isDarkMode ? "#e0e0e0" : "#000";
|
|
||||||
modalContent.style.border = isDarkMode ? "1px solid #444" : "1px solid #ccc";
|
|
||||||
}
|
|
||||||
document.getElementById("oidcProviderUrl").value = window.currentOIDCConfig.providerUrl;
|
|
||||||
document.getElementById("oidcClientId").value = window.currentOIDCConfig.clientId;
|
|
||||||
document.getElementById("oidcClientSecret").value = window.currentOIDCConfig.clientSecret;
|
|
||||||
document.getElementById("oidcRedirectUri").value = window.currentOIDCConfig.redirectUri;
|
|
||||||
document.getElementById("globalOtpauthUrl").value = window.currentOIDCConfig.globalOtpauthUrl || 'otpauth://totp/{label}?secret={secret}&issuer=FileRise';
|
|
||||||
document.getElementById("disableFormLogin").checked = config.loginOptions.disableFormLogin === true;
|
|
||||||
document.getElementById("disableBasicAuth").checked = config.loginOptions.disableBasicAuth === true;
|
|
||||||
document.getElementById("disableOIDCLogin").checked = config.loginOptions.disableOIDCLogin === true;
|
|
||||||
adminModal.style.display = "flex";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
let adminModal = document.getElementById("adminPanelModal");
|
|
||||||
if (adminModal) {
|
|
||||||
adminModal.style.backgroundColor = "rgba(0,0,0,0.5)";
|
|
||||||
const modalContent = adminModal.querySelector(".modal-content");
|
|
||||||
if (modalContent) {
|
|
||||||
modalContent.style.background = "#fff";
|
|
||||||
modalContent.style.color = "#000";
|
|
||||||
modalContent.style.border = "1px solid #ccc";
|
|
||||||
}
|
|
||||||
document.getElementById("oidcProviderUrl").value = window.currentOIDCConfig.providerUrl;
|
|
||||||
document.getElementById("oidcClientId").value = window.currentOIDCConfig.clientId;
|
|
||||||
document.getElementById("oidcClientSecret").value = window.currentOIDCConfig.clientSecret;
|
|
||||||
document.getElementById("oidcRedirectUri").value = window.currentOIDCConfig.redirectUri;
|
|
||||||
document.getElementById("globalOtpauthUrl").value = window.currentOIDCConfig.globalOtpauthUrl || 'otpauth://totp/{label}?secret={secret}&issuer=FileRise';
|
|
||||||
document.getElementById("disableFormLogin").checked = localStorage.getItem("disableFormLogin") === "true";
|
|
||||||
document.getElementById("disableBasicAuth").checked = localStorage.getItem("disableBasicAuth") === "true";
|
|
||||||
document.getElementById("disableOIDCLogin").checked = localStorage.getItem("disableOIDCLogin") === "true";
|
|
||||||
adminModal.style.display = "flex";
|
|
||||||
} else {
|
|
||||||
openAdminPanel();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
document.getElementById("cancelAdminSettings").addEventListener("click", closeAdminPanel);
|
||||||
|
document.getElementById("adminOpenAddUser").addEventListener("click", () => {
|
||||||
|
toggleVisibility("addUserModal", true);
|
||||||
|
document.getElementById("newUsername").focus();
|
||||||
|
});
|
||||||
|
document.getElementById("adminOpenRemoveUser").addEventListener("click", () => {
|
||||||
|
if (typeof window.loadUserList === "function") {
|
||||||
|
window.loadUserList();
|
||||||
|
}
|
||||||
|
toggleVisibility("removeUserModal", true);
|
||||||
|
});
|
||||||
|
// New event binding for the User Permissions button:
|
||||||
|
document.getElementById("adminOpenUserPermissions").addEventListener("click", () => {
|
||||||
|
openUserPermissionsModal();
|
||||||
|
});
|
||||||
|
document.getElementById("saveAdminSettings").addEventListener("click", () => {
|
||||||
|
const disableFormLoginCheckbox = document.getElementById("disableFormLogin");
|
||||||
|
const disableBasicAuthCheckbox = document.getElementById("disableBasicAuth");
|
||||||
|
const disableOIDCLoginCheckbox = document.getElementById("disableOIDCLogin");
|
||||||
|
const totalDisabled = [disableFormLoginCheckbox, disableBasicAuthCheckbox, disableOIDCLoginCheckbox].filter(cb => cb.checked).length;
|
||||||
|
if (totalDisabled === 3) {
|
||||||
|
showToast("At least one login method must remain enabled.");
|
||||||
|
disableOIDCLoginCheckbox.checked = false;
|
||||||
|
localStorage.setItem("disableOIDCLogin", "false");
|
||||||
|
if (typeof window.updateLoginOptionsUI === "function") {
|
||||||
|
window.updateLoginOptionsUI({
|
||||||
|
disableFormLogin: disableFormLoginCheckbox.checked,
|
||||||
|
disableBasicAuth: disableBasicAuthCheckbox.checked,
|
||||||
|
disableOIDCLogin: disableOIDCLoginCheckbox.checked
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const newOIDCConfig = {
|
||||||
|
providerUrl: document.getElementById("oidcProviderUrl").value.trim(),
|
||||||
|
clientId: document.getElementById("oidcClientId").value.trim(),
|
||||||
|
clientSecret: document.getElementById("oidcClientSecret").value.trim(),
|
||||||
|
redirectUri: document.getElementById("oidcRedirectUri").value.trim()
|
||||||
|
};
|
||||||
|
const disableFormLogin = disableFormLoginCheckbox.checked;
|
||||||
|
const disableBasicAuth = disableBasicAuthCheckbox.checked;
|
||||||
|
const disableOIDCLogin = disableOIDCLoginCheckbox.checked;
|
||||||
|
const globalOtpauthUrl = document.getElementById("globalOtpauthUrl").value.trim();
|
||||||
|
sendRequest("updateConfig.php", "POST", {
|
||||||
|
oidc: newOIDCConfig,
|
||||||
|
disableFormLogin,
|
||||||
|
disableBasicAuth,
|
||||||
|
disableOIDCLogin,
|
||||||
|
globalOtpauthUrl
|
||||||
|
}, { "X-CSRF-Token": window.csrfToken })
|
||||||
|
.then(response => {
|
||||||
|
if (response.success) {
|
||||||
|
showToast("Settings updated successfully.");
|
||||||
|
localStorage.setItem("disableFormLogin", disableFormLogin);
|
||||||
|
localStorage.setItem("disableBasicAuth", disableBasicAuth);
|
||||||
|
localStorage.setItem("disableOIDCLogin", disableOIDCLogin);
|
||||||
|
if (typeof window.updateLoginOptionsUI === "function") {
|
||||||
|
window.updateLoginOptionsUI({ disableFormLogin, disableBasicAuth, disableOIDCLogin });
|
||||||
|
}
|
||||||
|
closeAdminPanel();
|
||||||
|
} else {
|
||||||
|
showToast("Error updating settings: " + (response.error || "Unknown error"));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => { });
|
||||||
|
});
|
||||||
|
const disableFormLoginCheckbox = document.getElementById("disableFormLogin");
|
||||||
|
const disableBasicAuthCheckbox = document.getElementById("disableBasicAuth");
|
||||||
|
const disableOIDCLoginCheckbox = document.getElementById("disableOIDCLogin");
|
||||||
|
function enforceLoginOptionConstraint(changedCheckbox) {
|
||||||
|
const totalDisabled = [disableFormLoginCheckbox, disableBasicAuthCheckbox, disableOIDCLoginCheckbox].filter(cb => cb.checked).length;
|
||||||
|
if (changedCheckbox.checked && totalDisabled === 3) {
|
||||||
|
showToast("At least one login method must remain enabled.");
|
||||||
|
changedCheckbox.checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
disableFormLoginCheckbox.addEventListener("change", function () { enforceLoginOptionConstraint(this); });
|
||||||
|
disableBasicAuthCheckbox.addEventListener("change", function () { enforceLoginOptionConstraint(this); });
|
||||||
|
disableOIDCLoginCheckbox.addEventListener("change", function () { enforceLoginOptionConstraint(this); });
|
||||||
|
|
||||||
|
document.getElementById("disableFormLogin").checked = config.loginOptions.disableFormLogin === true;
|
||||||
|
document.getElementById("disableBasicAuth").checked = config.loginOptions.disableBasicAuth === true;
|
||||||
|
document.getElementById("disableOIDCLogin").checked = config.loginOptions.disableOIDCLogin === true;
|
||||||
|
} else {
|
||||||
|
adminModal.style.backgroundColor = overlayBackground;
|
||||||
|
const modalContent = adminModal.querySelector(".modal-content");
|
||||||
|
if (modalContent) {
|
||||||
|
modalContent.style.background = isDarkMode ? "#2c2c2c" : "#fff";
|
||||||
|
modalContent.style.color = isDarkMode ? "#e0e0e0" : "#000";
|
||||||
|
modalContent.style.border = isDarkMode ? "1px solid #444" : "1px solid #ccc";
|
||||||
|
}
|
||||||
|
document.getElementById("oidcProviderUrl").value = window.currentOIDCConfig.providerUrl;
|
||||||
|
document.getElementById("oidcClientId").value = window.currentOIDCConfig.clientId;
|
||||||
|
document.getElementById("oidcClientSecret").value = window.currentOIDCConfig.clientSecret;
|
||||||
|
document.getElementById("oidcRedirectUri").value = window.currentOIDCConfig.redirectUri;
|
||||||
|
document.getElementById("globalOtpauthUrl").value = window.currentOIDCConfig.globalOtpauthUrl || 'otpauth://totp/{label}?secret={secret}&issuer=FileRise';
|
||||||
|
document.getElementById("disableFormLogin").checked = config.loginOptions.disableFormLogin === true;
|
||||||
|
document.getElementById("disableBasicAuth").checked = config.loginOptions.disableBasicAuth === true;
|
||||||
|
document.getElementById("disableOIDCLogin").checked = config.loginOptions.disableOIDCLogin === true;
|
||||||
|
adminModal.style.display = "flex";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
let adminModal = document.getElementById("adminPanelModal");
|
||||||
|
if (adminModal) {
|
||||||
|
adminModal.style.backgroundColor = "rgba(0,0,0,0.5)";
|
||||||
|
const modalContent = adminModal.querySelector(".modal-content");
|
||||||
|
if (modalContent) {
|
||||||
|
modalContent.style.background = "#fff";
|
||||||
|
modalContent.style.color = "#000";
|
||||||
|
modalContent.style.border = "1px solid #ccc";
|
||||||
|
}
|
||||||
|
document.getElementById("oidcProviderUrl").value = window.currentOIDCConfig.providerUrl;
|
||||||
|
document.getElementById("oidcClientId").value = window.currentOIDCConfig.clientId;
|
||||||
|
document.getElementById("oidcClientSecret").value = window.currentOIDCConfig.clientSecret;
|
||||||
|
document.getElementById("oidcRedirectUri").value = window.currentOIDCConfig.redirectUri;
|
||||||
|
document.getElementById("globalOtpauthUrl").value = window.currentOIDCConfig.globalOtpauthUrl || 'otpauth://totp/{label}?secret={secret}&issuer=FileRise';
|
||||||
|
document.getElementById("disableFormLogin").checked = localStorage.getItem("disableFormLogin") === "true";
|
||||||
|
document.getElementById("disableBasicAuth").checked = localStorage.getItem("disableBasicAuth") === "true";
|
||||||
|
document.getElementById("disableOIDCLogin").checked = localStorage.getItem("disableOIDCLogin") === "true";
|
||||||
|
adminModal.style.display = "flex";
|
||||||
|
} else {
|
||||||
|
openAdminPanel();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function closeAdminPanel() {
|
export function closeAdminPanel() {
|
||||||
const adminModal = document.getElementById("adminPanelModal");
|
const adminModal = document.getElementById("adminPanelModal");
|
||||||
if (adminModal) adminModal.style.display = "none";
|
if (adminModal) adminModal.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- New: User Permissions Modal ---
|
// --- New: User Permissions Modal ---
|
||||||
|
|
||||||
export function openUserPermissionsModal() {
|
export function openUserPermissionsModal() {
|
||||||
let userPermissionsModal = document.getElementById("userPermissionsModal");
|
let userPermissionsModal = document.getElementById("userPermissionsModal");
|
||||||
const isDarkMode = document.body.classList.contains("dark-mode");
|
const isDarkMode = document.body.classList.contains("dark-mode");
|
||||||
const overlayBackground = isDarkMode ? "rgba(0,0,0,0.7)" : "rgba(0,0,0,0.3)";
|
const overlayBackground = isDarkMode ? "rgba(0,0,0,0.7)" : "rgba(0,0,0,0.3)";
|
||||||
const modalContentStyles = `
|
const modalContentStyles = `
|
||||||
background: ${isDarkMode ? "#2c2c2c" : "#fff"};
|
background: ${isDarkMode ? "#2c2c2c" : "#fff"};
|
||||||
color: ${isDarkMode ? "#e0e0e0" : "#000"};
|
color: ${isDarkMode ? "#e0e0e0" : "#000"};
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
@@ -666,10 +677,10 @@ export function openUserPermissionsModal() {
|
|||||||
position: relative;
|
position: relative;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
if (!userPermissionsModal) {
|
if (!userPermissionsModal) {
|
||||||
userPermissionsModal = document.createElement("div");
|
userPermissionsModal = document.createElement("div");
|
||||||
userPermissionsModal.id = "userPermissionsModal";
|
userPermissionsModal.id = "userPermissionsModal";
|
||||||
userPermissionsModal.style.cssText = `
|
userPermissionsModal.style.cssText = `
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -681,7 +692,7 @@ export function openUserPermissionsModal() {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 3500;
|
z-index: 3500;
|
||||||
`;
|
`;
|
||||||
userPermissionsModal.innerHTML = `
|
userPermissionsModal.innerHTML = `
|
||||||
<div class="modal-content" style="${modalContentStyles}">
|
<div class="modal-content" style="${modalContentStyles}">
|
||||||
<span id="closeUserPermissionsModal" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 24px;">×</span>
|
<span id="closeUserPermissionsModal" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 24px;">×</span>
|
||||||
<h3>User Permissions</h3>
|
<h3>User Permissions</h3>
|
||||||
@@ -694,86 +705,86 @@ export function openUserPermissionsModal() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
document.body.appendChild(userPermissionsModal);
|
document.body.appendChild(userPermissionsModal);
|
||||||
document.getElementById("closeUserPermissionsModal").addEventListener("click", () => {
|
document.getElementById("closeUserPermissionsModal").addEventListener("click", () => {
|
||||||
|
userPermissionsModal.style.display = "none";
|
||||||
|
});
|
||||||
|
document.getElementById("cancelUserPermissionsBtn").addEventListener("click", () => {
|
||||||
|
userPermissionsModal.style.display = "none";
|
||||||
|
});
|
||||||
|
document.getElementById("saveUserPermissionsBtn").addEventListener("click", () => {
|
||||||
|
// Collect permissions data from each user row.
|
||||||
|
const rows = userPermissionsModal.querySelectorAll(".user-permission-row");
|
||||||
|
const permissionsData = [];
|
||||||
|
rows.forEach(row => {
|
||||||
|
const username = row.getAttribute("data-username");
|
||||||
|
const folderOnlyCheckbox = row.querySelector("input[data-permission='folderOnly']");
|
||||||
|
const readOnlyCheckbox = row.querySelector("input[data-permission='readOnly']");
|
||||||
|
const disableUploadCheckbox = row.querySelector("input[data-permission='disableUpload']");
|
||||||
|
permissionsData.push({
|
||||||
|
username,
|
||||||
|
folderOnly: folderOnlyCheckbox.checked,
|
||||||
|
readOnly: readOnlyCheckbox.checked,
|
||||||
|
disableUpload: disableUploadCheckbox.checked
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// Send the permissionsData to the server.
|
||||||
|
sendRequest("updateUserPermissions.php", "POST", { permissions: permissionsData }, { "X-CSRF-Token": window.csrfToken })
|
||||||
|
.then(response => {
|
||||||
|
if (response.success) {
|
||||||
|
showToast("User permissions updated successfully.");
|
||||||
userPermissionsModal.style.display = "none";
|
userPermissionsModal.style.display = "none";
|
||||||
|
} else {
|
||||||
|
showToast("Error updating permissions: " + (response.error || "Unknown error"));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
showToast("Error updating permissions.");
|
||||||
});
|
});
|
||||||
document.getElementById("cancelUserPermissionsBtn").addEventListener("click", () => {
|
});
|
||||||
userPermissionsModal.style.display = "none";
|
} else {
|
||||||
});
|
userPermissionsModal.style.display = "flex";
|
||||||
document.getElementById("saveUserPermissionsBtn").addEventListener("click", () => {
|
}
|
||||||
// Collect permissions data from each user row.
|
// Load the list of users into the modal.
|
||||||
const rows = userPermissionsModal.querySelectorAll(".user-permission-row");
|
loadUserPermissionsList();
|
||||||
const permissionsData = [];
|
|
||||||
rows.forEach(row => {
|
|
||||||
const username = row.getAttribute("data-username");
|
|
||||||
const folderOnlyCheckbox = row.querySelector("input[data-permission='folderOnly']");
|
|
||||||
const readOnlyCheckbox = row.querySelector("input[data-permission='readOnly']");
|
|
||||||
const disableUploadCheckbox = row.querySelector("input[data-permission='disableUpload']");
|
|
||||||
permissionsData.push({
|
|
||||||
username,
|
|
||||||
folderOnly: folderOnlyCheckbox.checked,
|
|
||||||
readOnly: readOnlyCheckbox.checked,
|
|
||||||
disableUpload: disableUploadCheckbox.checked
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// Send the permissionsData to the server.
|
|
||||||
sendRequest("updateUserPermissions.php", "POST", { permissions: permissionsData }, { "X-CSRF-Token": window.csrfToken })
|
|
||||||
.then(response => {
|
|
||||||
if (response.success) {
|
|
||||||
showToast("User permissions updated successfully.");
|
|
||||||
userPermissionsModal.style.display = "none";
|
|
||||||
} else {
|
|
||||||
showToast("Error updating permissions: " + (response.error || "Unknown error"));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
showToast("Error updating permissions.");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
userPermissionsModal.style.display = "flex";
|
|
||||||
}
|
|
||||||
// Load the list of users into the modal.
|
|
||||||
loadUserPermissionsList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadUserPermissionsList() {
|
function loadUserPermissionsList() {
|
||||||
const listContainer = document.getElementById("userPermissionsList");
|
const listContainer = document.getElementById("userPermissionsList");
|
||||||
if (!listContainer) return;
|
if (!listContainer) return;
|
||||||
listContainer.innerHTML = "";
|
listContainer.innerHTML = "";
|
||||||
|
|
||||||
// First, fetch the current permissions from the server.
|
// First, fetch the current permissions from the server.
|
||||||
fetch("getUserPermissions.php", { credentials: "include" })
|
fetch("getUserPermissions.php", { credentials: "include" })
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(permissionsData => {
|
||||||
|
// Then, fetch the list of users.
|
||||||
|
return fetch("getUsers.php", { credentials: "include" })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(permissionsData => {
|
.then(usersData => {
|
||||||
// Then, fetch the list of users.
|
const users = Array.isArray(usersData) ? usersData : (usersData.users || []);
|
||||||
return fetch("getUsers.php", { credentials: "include" })
|
if (users.length === 0) {
|
||||||
.then(response => response.json())
|
listContainer.innerHTML = "<p>No users found.</p>";
|
||||||
.then(usersData => {
|
return;
|
||||||
const users = Array.isArray(usersData) ? usersData : (usersData.users || []);
|
}
|
||||||
if (users.length === 0) {
|
users.forEach(user => {
|
||||||
listContainer.innerHTML = "<p>No users found.</p>";
|
// Skip admin users.
|
||||||
return;
|
if ((user.role && user.role === "1") || user.username.toLowerCase() === "admin") return;
|
||||||
}
|
|
||||||
users.forEach(user => {
|
|
||||||
// Skip admin users.
|
|
||||||
if ((user.role && user.role === "1") || user.username.toLowerCase() === "admin") return;
|
|
||||||
|
|
||||||
// Use stored permissions if available; otherwise fall back to localStorage defaults.
|
// Use stored permissions if available; otherwise fall back to localStorage defaults.
|
||||||
const defaultPerm = {
|
const defaultPerm = {
|
||||||
folderOnly: localStorage.getItem("folderOnly") === "true",
|
folderOnly: localStorage.getItem("folderOnly") === "true",
|
||||||
readOnly: localStorage.getItem("readOnly") === "true",
|
readOnly: localStorage.getItem("readOnly") === "true",
|
||||||
disableUpload: localStorage.getItem("disableUpload") === "true"
|
disableUpload: localStorage.getItem("disableUpload") === "true"
|
||||||
};
|
};
|
||||||
const userPerm = (permissionsData && typeof permissionsData === "object" && permissionsData[user.username]) || defaultPerm;
|
const userPerm = (permissionsData && typeof permissionsData === "object" && permissionsData[user.username]) || defaultPerm;
|
||||||
|
|
||||||
// Create a row for the user.
|
// Create a row for the user.
|
||||||
const row = document.createElement("div");
|
const row = document.createElement("div");
|
||||||
row.classList.add("user-permission-row");
|
row.classList.add("user-permission-row");
|
||||||
row.setAttribute("data-username", user.username);
|
row.setAttribute("data-username", user.username);
|
||||||
row.style.padding = "10px 0";
|
row.style.padding = "10px 0";
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<div style="font-weight: bold; margin-bottom: 5px;">${user.username}</div>
|
<div style="font-weight: bold; margin-bottom: 5px;">${user.username}</div>
|
||||||
<div style="display: flex; flex-direction: column; gap: 5px;">
|
<div style="display: flex; flex-direction: column; gap: 5px;">
|
||||||
<label style="display: flex; align-items: center; gap: 5px;">
|
<label style="display: flex; align-items: center; gap: 5px;">
|
||||||
@@ -791,11 +802,11 @@ function loadUserPermissionsList() {
|
|||||||
</div>
|
</div>
|
||||||
<hr style="margin-top: 10px; border: 0; border-bottom: 1px solid #ccc;">
|
<hr style="margin-top: 10px; border: 0; border-bottom: 1px solid #ccc;">
|
||||||
`;
|
`;
|
||||||
listContainer.appendChild(row);
|
listContainer.appendChild(row);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
listContainer.innerHTML = "<p>Error loading users.</p>";
|
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
listContainer.innerHTML = "<p>Error loading users.</p>";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user