adlerka.top/templates/userActions.html

148 lines
5.3 KiB
HTML
Raw Normal View History

2024-02-03 16:08:26 +01:00
<script>
function changePassword() {
2024-02-03 17:55:54 +01:00
const oldPassword = document.getElementById("changeoldPassword").value;
2024-02-03 16:08:26 +01:00
const newPassword = document.getElementById("changeNewPassword").value;
const data = new URLSearchParams();
data.append("action", "change_password");
2024-02-03 17:55:54 +01:00
data.append("old_password", oldPassword);
2024-02-03 16:08:26 +01:00
data.append("new_password", newPassword);
doChangePassword(data, "Password change Successful!", "Password change failed.");
}
function doChangePassword(requestData, successMessage, failureMessage) {
2024-02-03 17:01:52 +01:00
doAccountAction(requestData, successMessage, failureMessage);
2024-02-03 16:08:26 +01:00
}
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);
2024-02-03 17:01:52 +01:00
doAccountAction(data, "Profile update Successful!", "Profile update failed.");
2024-02-03 16:08:26 +01:00
}
2024-02-03 17:30:51 +01:00
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.");
}
2024-02-04 09:19:35 +01:00
function populateUserInfoFields(userData) {
document.getElementById("updateFirstName").value = userData.first_name || "";
document.getElementById("updateLastName").value = userData.last_name || "";
document.getElementById("updateNickname").value = userData.nickname || "";
document.getElementById("updateMinecraftNick").value = userData.minecraft_nick || "";
document.getElementById("updateNewEmail").value = userData.Email || "";
}
2024-02-03 16:08:26 +01:00
async function getUserInfo() {
const data = new URLSearchParams();
data.append("action", "get_user_info");
2024-02-04 09:19:35 +01:00
const result = await doAccountAction(data, "User info retrieved Successfully!", "User info retrieval failed.", true);
2024-02-03 16:08:26 +01:00
if (result && result.Status === "Success") {
2024-02-04 09:19:35 +01:00
populateUserInfoFields(result.UserInfo);
2024-02-03 16:08:26 +01:00
}
}
2024-02-04 09:19:35 +01:00
function init(){
getUserInfo();
}
2024-02-03 16:08:26 +01:00
function displayUserInfo(userData) {
const tableContainer = document.getElementById("userInfoTable");
tableContainer.innerHTML = ""; // Clear previous content
const table = document.createElement("table");
table.border = "1";
const headerRow = table.insertRow(0);
for (const key in userData) {
const th = document.createElement("th");
th.appendChild(document.createTextNode(key));
headerRow.appendChild(th);
}
const dataRow = table.insertRow(1);
for (const key in userData) {
const td = document.createElement("td");
td.appendChild(document.createTextNode(userData[key]));
dataRow.appendChild(td);
}
tableContainer.appendChild(table);
}
2024-02-04 09:19:35 +01:00
window.onload = init();
2024-02-03 16:08:26 +01:00
</script>
2024-02-03 17:35:45 +01:00
<!-- Centralized Status Message -->
<p id="StatusMessage"></p>
2024-02-03 17:37:56 +01:00
<table id="userInfoTable"></table>
2024-02-03 16:08:26 +01:00
<div class="form-container" id="changePasswordForm">
<h1>Change Password</h1>
<form>
<label for="changeOldPassword">Old Password:</label>
2024-02-03 17:55:54 +01:00
<input type="password" id="changeOldPassword" name="changeOldPassword" required><br>
2024-02-03 16:08:26 +01:00
<label for="changeNewPassword">New Password:</label>
2024-02-03 17:55:54 +01:00
<input type="password" id="changeNewPassword" name="changeNewPassword" required><br>
2024-02-03 16:08:26 +01:00
<button type="button" onclick="changePassword()">Change Password</button>
2024-02-03 17:55:54 +01:00
</form><br>
2024-02-03 16:08:26 +01:00
</div>
<div class="form-container" id="updateUserProfileForm">
<h1>Update User Profile</h1>
<form>
<label for="updateFirstName">First Name:</label>
2024-02-03 17:55:54 +01:00
<input type="text" id="updateFirstName" name="updateFirstName" required><br>
2024-02-03 16:08:26 +01:00
<label for="updateLastName">Last Name:</label>
2024-02-03 17:55:54 +01:00
<input type="text" id="updateLastName" name="updateLastName" required><br>
2024-02-03 16:08:26 +01:00
<label for="updateNickname">Nickname:</label>
2024-02-03 17:55:54 +01:00
<input type="text" id="updateNickname" name="updateNickname" required><br>
2024-02-03 16:08:26 +01:00
<label for="updateMinecraftNick">Minecraft Nick:</label>
2024-02-03 17:55:54 +01:00
<input type="text" id="updateMinecraftNick" name="updateMinecraftNick" required><br>
2024-02-03 16:08:26 +01:00
<button type="button" onclick="updateUserProfile()">Update Profile</button>
2024-02-03 17:55:54 +01:00
</form><br>
2024-02-03 16:08:26 +01:00
</div>
<div class="form-container" id="getUserInfoForm">
<h1>Get User Info</h1>
<form>
<button type="button" onclick="getUserInfo()">Get User Info</button>
2024-02-03 17:55:54 +01:00
</form><br>
2024-02-03 16:08:26 +01:00
</div>
2024-02-03 17:30:51 +01:00
<div class="form-container" id="updateUserEmailForm">
<h1>Update User Email</h1>
<form>
<label for="updateNewEmail">New Email:</label>
2024-02-03 17:55:54 +01:00
<input type="email" id="updateNewEmail" name="updateNewEmail" required><br>
2024-02-03 17:30:51 +01:00
<button type="button" onclick="updateEmail()">Update Email</button>
2024-02-03 17:55:54 +01:00
</form><br>
2024-02-03 17:30:51 +01:00
</div>
2024-02-03 17:55:54 +01:00
<button type="button" onclick="logout()">Logout</button><br>