2024-02-03 22:44:01 +01:00
|
|
|
function doAccountAction(requestData, successMessage, failureMessage, silent=false) {
|
2024-02-03 17:01:52 +01:00
|
|
|
return fetch('/account', {
|
2024-02-03 16:08:26 +01:00
|
|
|
method: 'POST',
|
|
|
|
body: requestData,
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then(data => {
|
2024-02-03 22:44:01 +01:00
|
|
|
if(!silent) {
|
|
|
|
handleResponse(data, successMessage, failureMessage);
|
|
|
|
}
|
2024-02-03 16:08:26 +01:00
|
|
|
return data; // Returning the response data for further processing
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Error:', error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleResponse(data, SuccessMessage, failureMessage) {
|
|
|
|
const StatusMessageElement = document.getElementById("StatusMessage");
|
|
|
|
|
|
|
|
if (data.Status === 'Success') {
|
|
|
|
StatusMessageElement.innerText = SuccessMessage;
|
|
|
|
} else {
|
|
|
|
StatusMessageElement.innerText = failureMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout() {
|
|
|
|
const data = new URLSearchParams();
|
|
|
|
data.append("action", "logout");
|
|
|
|
|
2024-02-03 17:01:52 +01:00
|
|
|
doAccountAction(data, "Logout Successful!", "Logout failed.");
|
2024-02-03 16:08:26 +01:00
|
|
|
}
|
|
|
|
|