MCPcopy Create free account
hub / github.com/error311/FileRise / initAuth

Function initAuth

public/js/auth.js:856–1008  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

854window.loadUserList = loadUserList;
855
856function 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);

Callers

nothing calls this directly

Calls 12

checkAuthenticationFunction · 0.85
loadAdminConfigFuncFunction · 0.85
submitLoginFunction · 0.85
resetUserFormFunction · 0.85
toggleVisibilityFunction · 0.85
tFunction · 0.85
fetchWithCsrfFunction · 0.85
closeAddUserModalFunction · 0.85
loadUserListFunction · 0.85
closeRemoveUserModalFunction · 0.85
showToastFunction · 0.70
showCustomConfirmModalFunction · 0.70

Tested by

no test coverage detected