// Authentication functions
function isAdminLoggedIn() {
return sessionStorage.getItem('adminToken') !== null;
}
function isUserLoggedIn() {
return sessionStorage.getItem('userToken') !== null;
}
function requireAdminAuth() {
if (!isAdminLoggedIn()) {
window.location.href = 'admin-login.html';
return false;
}
return true;
}
function requireUserAuth() {
if (!isUserLoggedIn()) {
window.location.href = 'signup.html';
return false;
}
return true;
}
// Generate QR code for 2FA
function generateQRCode(secret, label) {
const qrUrl = `otpauth://totp/${encodeURIComponent(label)}?secret=${secret}&issuer=Fuse%20Cafe`;
const qrCode = new QRCode(document.createElement('div'), {
text: qrUrl,
width: 128,
height: 128,
colorDark: "#5a3c2b",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
});
return qrCode._el.firstChild;
}
// Include libraries
const QRCode = typeof window !== 'undefined' ? window.QRCode : require('qrcode');
// Initialize EmailJS
(function() {
emailjs.init("YOUR_EMAILJS_USER_ID"); // You'll need to get this from EmailJS
})();
// Main application logic
document.addEventListener('DOMContentLoaded', () => {
console.log('Fuse Cafe is ready!');
feather.replace();
// Sidebar minimize functionality
const sidebar = document.querySelector('custom-sidebar');
const minimizeBtn = document.getElementById('sidebar-minimize');
if (minimizeBtn) {
minimizeBtn.addEventListener('click', () => {
sidebar.style.transition = 'all 0.3s ease';
if (sidebar.style.width === '4rem') {
sidebar.style.width = '16rem';
minimizeBtn.innerHTML = '';
} else {
sidebar.style.width = '4rem';
minimizeBtn.innerHTML = '';
}
feather.replace();
});
}
// Form submission handler
const signupForm = document.querySelector('form');
if (signupForm) {
signupForm.addEventListener('submit', (e) => {
e.preventDefault();
alert('Account creation request received! We will contact you soon.');
window.location.href = 'index.html';
});
}
// Initialize local storage if not exists
if (!localStorage.getItem('fuseCafeData')) {
localStorage.setItem('fuseCafeData', JSON.stringify({
memories: [],
announcements: [],
shifts: [],
staff: [],
legal: {
tos: '',
privacy: ''
}
}));
}
});
// Animation triggers
const animateOnScroll = () => {
const elements = document.querySelectorAll('.animate-on-scroll');
elements.forEach(el => {
const elementTop = el.getBoundingClientRect().top;
if (elementTop < window.innerHeight - 100) {
el.classList.add('animate__animated', 'animate__fadeInUp');
}
});
};
window.addEventListener('scroll', animateOnScroll);
// Helper function to save data to local storage
function saveFuseCafeData(data) {
localStorage.setItem('fuseCafeData', JSON.stringify(data));
}
// Helper function to load data from local storage
function loadFuseCafeData() {
return JSON.parse(localStorage.getItem('fuseCafeData')) || {
memories: [],
announcements: [],
shifts: [],
staff: [],
legal: {
tos: '',
privacy: ''
}
};
}
// Initialize data on page load
function initializePageData() {
const data = loadFuseCafeData();
// Load memories if on memories page
if (document.getElementById('memories-container') && data.memories.length > 0) {
const container = document.getElementById('memories-container');
data.memories.forEach(memory => {
const memoryCard = document.createElement('div');
memoryCard.className = 'bg-white rounded-lg overflow-hidden shadow-md border border-[#e2d5c8]';
memoryCard.innerHTML = `
${memory.text || 'No description'}