forked from Adleraci/adlerka.top
Centralize scripts to fix ajax
This commit is contained in:
parent
554d2d93cb
commit
89d5cccc31
170
assets/script.js
170
assets/script.js
@ -172,3 +172,173 @@ function initAjax() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
document.addEventListener('DOMContentLoaded', initAjax);
|
document.addEventListener('DOMContentLoaded', initAjax);
|
||||||
|
|
||||||
|
|
||||||
|
//Login
|
||||||
|
|
||||||
|
function login() {
|
||||||
|
const email = document.getElementById("login_email").value;
|
||||||
|
const password = document.getElementById("login_password").value;
|
||||||
|
doLogin(email, password);
|
||||||
|
refreshNavbar();
|
||||||
|
softReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
function doLogin(email, password) {
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "login");
|
||||||
|
data.append("email", email);
|
||||||
|
data.append("password", password);
|
||||||
|
|
||||||
|
doAccountAction(data, "Login Successful!", "Login failed. Please check your credentials.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function register() {
|
||||||
|
const firstName = document.getElementById("register_firstName").value;
|
||||||
|
const lastName = document.getElementById("register_lastName").value;
|
||||||
|
const email = document.getElementById("register_email").value;
|
||||||
|
const password = document.getElementById("register_password").value;
|
||||||
|
const activationToken = document.getElementById("register_activationToken").value;
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "register");
|
||||||
|
data.append("firstname", firstName);
|
||||||
|
data.append("lastname", lastName);
|
||||||
|
data.append("email", email);
|
||||||
|
data.append("password", password);
|
||||||
|
data.append("activation_token", activationToken);
|
||||||
|
|
||||||
|
doRegister(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function doRegister(requestData) {
|
||||||
|
doAccountAction(requestData, "Registration Successful!", "Registration failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//User settings start
|
||||||
|
|
||||||
|
function changePassword() {
|
||||||
|
const oldPassword = document.getElementById("changeOldPassword").value;
|
||||||
|
const newPassword = document.getElementById("changeNewPassword").value;
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "change_password");
|
||||||
|
data.append("old_password", oldPassword);
|
||||||
|
data.append("new_password", newPassword);
|
||||||
|
|
||||||
|
doChangePassword(data, "Password change Successful!", "Password change failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function doChangePassword(requestData, successMessage, failureMessage) {
|
||||||
|
doAccountAction(requestData, successMessage, failureMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateUserProfile() {
|
||||||
|
const firstName = document.getElementById("updateFirstName").value;
|
||||||
|
const lastName = document.getElementById("updateLastName").value;
|
||||||
|
const nickname = document.getElementById("updateNickname").value;
|
||||||
|
const minecraftNick = document.getElementById("updateMinecraftNick").value;
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "update_user_profile");
|
||||||
|
data.append("first_name", firstName);
|
||||||
|
data.append("last_name", lastName);
|
||||||
|
data.append("nickname", nickname);
|
||||||
|
data.append("minecraft_nick", minecraftNick);
|
||||||
|
|
||||||
|
doAccountAction(data, "Profile update Successful!", "Profile update failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateEmail() {
|
||||||
|
const newEmail = document.getElementById("updateNewEmail").value;
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "update_user_email");
|
||||||
|
data.append("email", newEmail);
|
||||||
|
|
||||||
|
doAccountAction(data, "Email update Successful!", "Email update failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateUserInfoFields(userData) {
|
||||||
|
document.getElementById("updateFirstName").value = userData.FirstName || "";
|
||||||
|
document.getElementById("updateLastName").value = userData.LastName || "";
|
||||||
|
document.getElementById("updateNickname").value = userData.Nickname || "";
|
||||||
|
document.getElementById("updateMinecraftNick").value = userData.MinecraftNick || "";
|
||||||
|
document.getElementById("updateNewEmail").value = userData.Email || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getUserInfo() {
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "get_user_info");
|
||||||
|
|
||||||
|
const result = await doAccountAction(data, "User info retrieved Successfully!", "User info retrieval failed.", true);
|
||||||
|
|
||||||
|
if (result && result.Status === "Success") {
|
||||||
|
populateUserInfoFields(result.UserInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', getUserInfo);
|
||||||
|
|
||||||
|
//User settings end
|
||||||
|
|
||||||
|
//Admin settings start
|
||||||
|
|
||||||
|
async function addActivationCodes() {
|
||||||
|
const count = document.getElementById("activationCodeCount").value;
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "add_activation_codes");
|
||||||
|
data.append("count", count);
|
||||||
|
|
||||||
|
const result = await doAccountAction(data, "Activation codes added Successfully!", "Activation codes addition failed.");
|
||||||
|
|
||||||
|
displayList(result.ActivationCodes, "codeListTable", deleteActivationCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listUsers() {
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "list_users");
|
||||||
|
|
||||||
|
const result = await doAccountAction(data, "User list retrieved Successfully!", "User list retrieval failed.");
|
||||||
|
|
||||||
|
if (result && result.Status === "Success") {
|
||||||
|
displayList(result.Users, "userListTable", deleteUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function listActivationCodes() {
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "list_activation_codes");
|
||||||
|
|
||||||
|
const result = await doAccountAction(data, "Activation code list retrieved Successfully!", "Activation code list retrieval failed.");
|
||||||
|
|
||||||
|
displayList(result.ActivationCodes, "codeListTable", deleteActivationCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteUser(userId) {
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "delete_user");
|
||||||
|
data.append("user_id", userId);
|
||||||
|
|
||||||
|
doAccountAction(data, "User deleted Successfully!", "User deletion failed.");
|
||||||
|
listUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteActivationCode(activationCode) {
|
||||||
|
|
||||||
|
const data = new URLSearchParams();
|
||||||
|
data.append("action", "delete_activation_code");
|
||||||
|
data.append("activation_code", activationCode);
|
||||||
|
|
||||||
|
doAccountAction(data, "Activation code deleted Successfully!", "Activation code deletion failed.");
|
||||||
|
listActivationCodes();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', listUsers);
|
||||||
|
document.addEventListener('DOMContentLoaded', listActivationCodes);
|
||||||
|
//Admin settings end
|
||||||
|
@ -1,64 +1,3 @@
|
|||||||
<script>
|
|
||||||
async function addActivationCodes() {
|
|
||||||
const count = document.getElementById("activationCodeCount").value;
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "add_activation_codes");
|
|
||||||
data.append("count", count);
|
|
||||||
|
|
||||||
const result = await doAccountAction(data, "Activation codes added Successfully!", "Activation codes addition failed.");
|
|
||||||
|
|
||||||
displayList(result.ActivationCodes, "codeListTable", deleteActivationCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function listUsers() {
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "list_users");
|
|
||||||
|
|
||||||
const result = await doAccountAction(data, "User list retrieved Successfully!", "User list retrieval failed.");
|
|
||||||
|
|
||||||
if (result && result.Status === "Success") {
|
|
||||||
displayList(result.Users, "userListTable", deleteUser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function listActivationCodes() {
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "list_activation_codes");
|
|
||||||
|
|
||||||
const result = await doAccountAction(data, "Activation code list retrieved Successfully!", "Activation code list retrieval failed.");
|
|
||||||
|
|
||||||
displayList(result.ActivationCodes, "codeListTable", deleteActivationCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteUser(userId) {
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "delete_user");
|
|
||||||
data.append("user_id", userId);
|
|
||||||
|
|
||||||
doAccountAction(data, "User deleted Successfully!", "User deletion failed.");
|
|
||||||
listUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteActivationCode(activationCode) {
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "delete_activation_code");
|
|
||||||
data.append("activation_code", activationCode);
|
|
||||||
|
|
||||||
doAccountAction(data, "Activation code deleted Successfully!", "Activation code deletion failed.");
|
|
||||||
listActivationCodes();
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script defer>
|
|
||||||
listActivationCodes();
|
|
||||||
listUsers();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="form-container" id="addActivationCodesForm">
|
<div class="form-container" id="addActivationCodesForm">
|
||||||
<h1>Activation Codes</h1>
|
<h1>Activation Codes</h1>
|
||||||
|
|
||||||
|
@ -1,45 +1,3 @@
|
|||||||
<script>
|
|
||||||
function login() {
|
|
||||||
const email = document.getElementById("login_email").value;
|
|
||||||
const password = document.getElementById("login_password").value;
|
|
||||||
doLogin(email, password);
|
|
||||||
refreshNavbar();
|
|
||||||
softReload();
|
|
||||||
}
|
|
||||||
|
|
||||||
function doLogin(email, password) {
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "login");
|
|
||||||
data.append("email", email);
|
|
||||||
data.append("password", password);
|
|
||||||
|
|
||||||
doAccountAction(data, "Login Successful!", "Login failed. Please check your credentials.");
|
|
||||||
}
|
|
||||||
|
|
||||||
function register() {
|
|
||||||
const firstName = document.getElementById("register_firstName").value;
|
|
||||||
const lastName = document.getElementById("register_lastName").value;
|
|
||||||
const email = document.getElementById("register_email").value;
|
|
||||||
const password = document.getElementById("register_password").value;
|
|
||||||
const activationToken = document.getElementById("register_activationToken").value;
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "register");
|
|
||||||
data.append("firstname", firstName);
|
|
||||||
data.append("lastname", lastName);
|
|
||||||
data.append("email", email);
|
|
||||||
data.append("password", password);
|
|
||||||
data.append("activation_token", activationToken);
|
|
||||||
|
|
||||||
doRegister(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function doRegister(requestData) {
|
|
||||||
doAccountAction(requestData, "Registration Successful!", "Registration failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Centralized Status Message -->
|
<!-- Centralized Status Message -->
|
||||||
<p id="StatusMessage"></p>
|
<p id="StatusMessage"></p>
|
||||||
|
|
||||||
|
@ -1,70 +1,3 @@
|
|||||||
<script>
|
|
||||||
function changePassword() {
|
|
||||||
const oldPassword = document.getElementById("changeOldPassword").value;
|
|
||||||
const newPassword = document.getElementById("changeNewPassword").value;
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "change_password");
|
|
||||||
data.append("old_password", oldPassword);
|
|
||||||
data.append("new_password", newPassword);
|
|
||||||
|
|
||||||
doChangePassword(data, "Password change Successful!", "Password change failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
function doChangePassword(requestData, successMessage, failureMessage) {
|
|
||||||
doAccountAction(requestData, successMessage, failureMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateUserProfile() {
|
|
||||||
const firstName = document.getElementById("updateFirstName").value;
|
|
||||||
const lastName = document.getElementById("updateLastName").value;
|
|
||||||
const nickname = document.getElementById("updateNickname").value;
|
|
||||||
const minecraftNick = document.getElementById("updateMinecraftNick").value;
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "update_user_profile");
|
|
||||||
data.append("first_name", firstName);
|
|
||||||
data.append("last_name", lastName);
|
|
||||||
data.append("nickname", nickname);
|
|
||||||
data.append("minecraft_nick", minecraftNick);
|
|
||||||
|
|
||||||
doAccountAction(data, "Profile update Successful!", "Profile update failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEmail() {
|
|
||||||
const newEmail = document.getElementById("updateNewEmail").value;
|
|
||||||
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "update_user_email");
|
|
||||||
data.append("email", newEmail);
|
|
||||||
|
|
||||||
doAccountAction(data, "Email update Successful!", "Email update failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
function populateUserInfoFields(userData) {
|
|
||||||
document.getElementById("updateFirstName").value = userData.FirstName || "";
|
|
||||||
document.getElementById("updateLastName").value = userData.LastName || "";
|
|
||||||
document.getElementById("updateNickname").value = userData.Nickname || "";
|
|
||||||
document.getElementById("updateMinecraftNick").value = userData.MinecraftNick || "";
|
|
||||||
document.getElementById("updateNewEmail").value = userData.Email || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getUserInfo() {
|
|
||||||
const data = new URLSearchParams();
|
|
||||||
data.append("action", "get_user_info");
|
|
||||||
|
|
||||||
const result = await doAccountAction(data, "User info retrieved Successfully!", "User info retrieval failed.", true);
|
|
||||||
|
|
||||||
if (result && result.Status === "Success") {
|
|
||||||
populateUserInfoFields(result.UserInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script defer>
|
|
||||||
getUserInfo();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Centralized Status Message -->
|
<!-- Centralized Status Message -->
|
||||||
<p id="StatusMessage"></p>
|
<p id="StatusMessage"></p>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user