42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
const logoutButton = document.getElementById('logout');
|
|
|
|
logoutButton.onclick = logout;
|
|
function logout() {
|
|
fetch('/auth/logout', {
|
|
method: 'POST',
|
|
credentials: 'include'
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
localStorage.clear();
|
|
window.location.href = '/login';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Logout failed:', error);
|
|
});
|
|
}
|
|
|
|
function togglePopup() {
|
|
const overlay = document.getElementById('popupOverlay');
|
|
overlay.classList.toggle('show');
|
|
}
|
|
|
|
// change password form
|
|
document.getElementById('changePasswordForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const cPassword = document.getElementById('cPassword').value.trim();
|
|
const nPassword = document.getElementById('nPassword').value.trim();
|
|
const messageBox = document.getElementById('messageBox');
|
|
const jsonData = JSON.stringify({ cPassword, nPassword });
|
|
const response = await fetch('/auth/changepassword', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: jsonData
|
|
});
|
|
const result = await response.json();
|
|
// Display result message
|
|
messageBox.innerText = result.message;
|
|
}) |