UI Admin aproape finalizat
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user