54 lines
2.1 KiB
JavaScript
54 lines
2.1 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function () {
|
|
const loginForm = document.getElementById('loginForm');
|
|
if (loginForm) {
|
|
loginForm.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
|
|
// Basic validation
|
|
if (!email || !password) {
|
|
showToast('Error', 'Please fill in all fields.', 'danger');
|
|
return;
|
|
}
|
|
|
|
// Simulate API call
|
|
showToast('Info', 'Attempting to log in...', 'info');
|
|
setTimeout(() => {
|
|
// Replace with actual authentication logic
|
|
if (email === 'admin@example.com' && password === 'password') {
|
|
showToast('Success', 'Login successful! Redirecting...', 'success');
|
|
} else {
|
|
showToast('Error', 'Invalid credentials. Please try again.', 'danger');
|
|
}
|
|
}, 1500);
|
|
});
|
|
}
|
|
});
|
|
|
|
function showToast(title, message, type) {
|
|
const toastContainer = document.getElementById('toast-container');
|
|
if (!toastContainer) return;
|
|
|
|
const toastId = 'toast-' + Date.now();
|
|
const toastHTML = `
|
|
<div id="${toastId}" class="toast align-items-center text-white bg-${type} border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="d-flex">
|
|
<div class="toast-body">
|
|
<strong>${title}:</strong> ${message}
|
|
</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
toastContainer.insertAdjacentHTML('beforeend', toastHTML);
|
|
const toastElement = document.getElementById(toastId);
|
|
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
|
|
toast.show();
|
|
|
|
toastElement.addEventListener('hidden.bs.toast', function () {
|
|
toastElement.remove();
|
|
});
|
|
}
|