adlerka.top/templates/userActions.html

110 lines
4.2 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) {
2024-02-04 09:21:00 +01:00
document.getElementById("updateFirstName").value = userData.FirstName || "";
document.getElementById("updateLastName").value = userData.LastName || "";
document.getElementById("updateNickname").value = userData.Nickname || "";
document.getElementById("updateMinecraftNick").value = userData.MinecraftNick || "";
2024-02-04 09:19:35 +01:00
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();
}
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 16:08:26 +01:00
<div class="form-container" id="updateUserProfileForm">
2024-02-04 09:26:17 +01:00
<h1>Update User</h1>
2024-02-03 16:08:26 +01:00
<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-04 09:26:17 +01:00
<label for="updateNewEmail">New Email:</label>
<input type="email" id="updateNewEmail" name="updateNewEmail" required><br>
<button type="button" onclick="updateEmail()">Update Email</button>
2024-02-03 17:55:54 +01:00
</form><br>
2024-02-03 16:08:26 +01:00
</div>
2024-02-04 09:26:17 +01:00
<div class="form-container" id="changePasswordForm">
<h1>Change Password</h1>
2024-02-03 17:30:51 +01:00
<form>
2024-02-04 09:26:17 +01:00
<label for="changeOldPassword">Old Password:</label>
<input type="password" id="changeOldPassword" name="changeOldPassword" required><br>
2024-02-03 17:30:51 +01:00
2024-02-04 09:26:17 +01:00
<label for="changeNewPassword">New Password:</label>
<input type="password" id="changeNewPassword" name="changeNewPassword" required><br>
<button type="button" onclick="changePassword()">Change Password</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>