gearza's picture
create booking system with login
0347414 verified
Raw History Blame Contribute Delete
4.46 kB
// Authentication functionality
function checkAuth() {
return localStorage.getItem('userToken') !== null;
}
function handleLogin(event) {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// In a real app, this would call an API
if ((username === 'admin' && password === 'pp888') ||
(username === 'user' && password === 'user123')) {
const token = btoa(`${username}:${Date.now()}`);
localStorage.setItem('userToken', token);
localStorage.setItem('username', username);
if (username === 'admin') {
window.location.href = '/admin';
} else {
window.location.href = '/';
}
} else {
alert('Invalid credentials');
}
}
function handleLogout() {
localStorage.removeItem('userToken');
localStorage.removeItem('username');
window.location.href = '/login.html';
}
// Admin features
function enableEditMode() {
if (!checkAuth()) return;
// Enable logo editing
const logo = document.querySelector('custom-navbar').shadowRoot.getElementById('logo-image');
logo.style.cursor = 'pointer';
logo.addEventListener('click', () => {
const newUrl = prompt('Enter new logo URL:', logo.src);
if (newUrl) {
logo.src = newUrl;
// In real app, save to backend here
}
});
// Enable footer editing
const footer = document.querySelector('custom-footer');
if (footer) {
footer.shadowRoot.querySelectorAll('.edit-btn').forEach(btn => {
btn.style.display = 'inline-block';
btn.addEventListener('click', (e) => {
const section = e.target.dataset.section;
const column = e.target.closest('.footer-column');
const content = column.innerHTML;
const newContent = prompt('Edit content (HTML):', content);
if (newContent) {
column.innerHTML = newContent;
// In real app, save to backend here
}
});
});
}
}
document.addEventListener('DOMContentLoaded', function() {
// Handle login form if exists
const loginForm = document.getElementById('loginForm');
if (loginForm) {
loginForm.addEventListener('submit', handleLogin);
}
// Enable admin features if authenticated
if (checkAuth()) {
enableEditMode();
}
// Initialize services carousel
const serviceCarousel = document.getElementById('service-carousel');
if (serviceCarousel) {
let currentIndex = 0;
const services = document.querySelectorAll('.service-item');
const totalServices = services.length;
function showService(index) {
services.forEach((service, i) => {
service.classList.toggle('hidden', i !== index);
service.classList.toggle('block', i === index);
});
}
document.getElementById('next-service').addEventListener('click', () => {
currentIndex = (currentIndex + 1) % totalServices;
showService(currentIndex);
});
document.getElementById('prev-service').addEventListener('click', () => {
currentIndex = (currentIndex - 1 + totalServices) % totalServices;
showService(currentIndex);
});
showService(0);
}
// Booking modal toggle
const bookingModal = document.getElementById('booking-modal');
const openBookingBtn = document.getElementById('open-booking');
const closeBookingBtn = document.getElementById('close-booking');
if (openBookingBtn && bookingModal) {
openBookingBtn.addEventListener('click', () => {
bookingModal.classList.remove('hidden');
document.body.classList.add('overflow-hidden');
});
closeBookingBtn.addEventListener('click', () => {
bookingModal.classList.add('hidden');
document.body.classList.remove('overflow-hidden');
});
}
// Initialize calendar
const calendarEl = document.getElementById('calendar');
if (calendarEl) {
// This would be replaced with actual calendar initialization
// For example, using FullCalendar.js in a real implementation
console.log('Calendar would be initialized here');
}
});