()
| 854 | window.loadUserList = loadUserList; |
| 855 | |
| 856 | function initAuth() { |
| 857 | checkAuthentication(false); |
| 858 | loadAdminConfigFunc(); |
| 859 | const authForm = document.getElementById("authForm"); |
| 860 | if (authForm) { |
| 861 | authForm.addEventListener("submit", function (event) { |
| 862 | event.preventDefault(); |
| 863 | const rememberMe = document.getElementById("rememberMeCheckbox") |
| 864 | ? document.getElementById("rememberMeCheckbox").checked |
| 865 | : false; |
| 866 | const formData = { |
| 867 | username: document.getElementById("loginUsername").value.trim(), |
| 868 | password: document.getElementById("loginPassword").value.trim(), |
| 869 | remember_me: rememberMe |
| 870 | }; |
| 871 | submitLogin(formData); |
| 872 | }); |
| 873 | } |
| 874 | |
| 875 | document.getElementById("addUserBtn").addEventListener("click", function () { |
| 876 | resetUserForm(); |
| 877 | toggleVisibility("addUserModal", true); |
| 878 | document.getElementById("newUsername").focus(); |
| 879 | }); |
| 880 | |
| 881 | // remove your old saveUserBtn click-handler… |
| 882 | |
| 883 | // instead: |
| 884 | const addUserForm = document.getElementById("addUserForm"); |
| 885 | addUserForm.addEventListener("submit", function (e) { |
| 886 | e.preventDefault(); // stop the browser from reloading the page |
| 887 | |
| 888 | const newUsername = document.getElementById("newUsername").value.trim(); |
| 889 | const newPassword = document.getElementById("addUserPassword").value.trim(); |
| 890 | const isAdmin = document.getElementById("isAdmin").checked; |
| 891 | |
| 892 | if (!newUsername || !newPassword) { |
| 893 | showToast(t('username_password_required')); |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | let url = "/api/admin/addUser.php"; |
| 898 | if (window.setupMode) url += "?setup=1"; |
| 899 | |
| 900 | fetchWithCsrf(url, { |
| 901 | method: "POST", |
| 902 | credentials: "include", |
| 903 | headers: { "Content-Type": "application/json" }, |
| 904 | body: JSON.stringify({ username: newUsername, password: newPassword, isAdmin }) |
| 905 | }) |
| 906 | .then(r => r.json()) |
| 907 | .then(data => { |
| 908 | if (data.success) { |
| 909 | showToast(t('user_add_success')); |
| 910 | closeAddUserModal(); |
| 911 | checkAuthentication(false); |
| 912 | if (window.setupMode) { |
| 913 | toggleVisibility("loginForm", true); |
nothing calls this directly
no test coverage detected