UI Admin aproape finalizat

This commit is contained in:
andrei-mihnea-cerbu
2024-04-03 02:09:12 +03:00
parent fb957a6f97
commit af8c295d75
134 changed files with 5014 additions and 1045 deletions
+38
View File
@@ -0,0 +1,38 @@
document.addEventListener('DOMContentLoaded', function () {
const loginForm = document.getElementById('loginForm');
loginForm.addEventListener('submit', async function (e) {
e.preventDefault();
const formData = new FormData(loginForm);
const email = formData.get('email');
const password = formData.get('password');
const data = { email, password };
try {
const response = await fetch('/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
const result = await response.json();
if (response.ok && result.success) {
// Set cookie with email and name
document.cookie = `email=${result.user.email};`;
document.cookie = `name=${result.user.name};`;
window.location.href = '/';
} else {
alert('Incorrect credentials. Please try again.');
}
} catch (error) {
console.error('Error during fetch:', error);
alert('An error occurred. Please try again.');
}
});
});