adlerka.top/templates/userActions.html
2024-02-04 09:26:17 +01:00

110 lines
4.2 KiB
HTML

<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);
}
}
function init(){
getUserInfo();
}
window.onload = init();
</script>
<!-- Centralized Status Message -->
<p id="StatusMessage"></p>
<div class="form-container" id="updateUserProfileForm">
<h1>Update User</h1>
<form>
<label for="updateFirstName">First Name:</label>
<input type="text" id="updateFirstName" name="updateFirstName" required><br>
<label for="updateLastName">Last Name:</label>
<input type="text" id="updateLastName" name="updateLastName" required><br>
<label for="updateNickname">Nickname:</label>
<input type="text" id="updateNickname" name="updateNickname" required><br>
<label for="updateMinecraftNick">Minecraft Nick:</label>
<input type="text" id="updateMinecraftNick" name="updateMinecraftNick" required><br>
<button type="button" onclick="updateUserProfile()">Update Profile</button>
<label for="updateNewEmail">New Email:</label>
<input type="email" id="updateNewEmail" name="updateNewEmail" required><br>
<button type="button" onclick="updateEmail()">Update Email</button>
</form><br>
</div>
<div class="form-container" id="changePasswordForm">
<h1>Change Password</h1>
<form>
<label for="changeOldPassword">Old Password:</label>
<input type="password" id="changeOldPassword" name="changeOldPassword" required><br>
<label for="changeNewPassword">New Password:</label>
<input type="password" id="changeNewPassword" name="changeNewPassword" required><br>
<button type="button" onclick="changePassword()">Change Password</button>
</form><br>
</div>
<button type="button" onclick="logout()">Logout</button><br>