CoolFace
Apppublic

Hellvor/gatekeeper-digital-bouncer

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
script.js62 linesDownload Raw Back to root
1document.addEventListener('DOMContentLoaded', function() {2    // Form validation3    const form = document.getElementById('authForm');4    5    if (form) {6        form.addEventListener('submit', function(e) {7            e.preventDefault();8            9            const email = document.getElementById('email-address').value;10            const password = document.getElementById('password').value;11            const rememberMe = document.getElementById('remember-me').checked;12            13            // Basic validation14            if (!email || !password) {15                showError('Please fill in all fields');16                return;17            }18            19            // Simulate authentication20            simulateAuthentication(email, password, rememberMe);21        });22    }23    24    function showError(message) {25        // In a real app, you'd show this to the user in a better way26        console.error(message);27        alert(message);28    }29    30    function simulateAuthentication(email, password, rememberMe) {31        // This is just a simulation - in a real app you'd call an API32        console.log(`Authentication attempt:`, { email, rememberMe });33        34        // Show loading state35        const submitButton = form.querySelector('button[type="submit"]');36        const originalText = submitButton.innerHTML;37        submitButton.innerHTML = `38            <span class="absolute left-0 inset-y-0 flex items-center pl-3">39                <i data-feather="loader" class="h-5 w-5 text-primary-200 animate-spin"></i>40            </span>41            Authenticating...42        `;43        feather.replace();44        45        // Simulate API call delay46        setTimeout(() => {47            // Reset button state48            submitButton.innerHTML = originalText;49            feather.replace();50            51            // In a real app, you'd redirect on success or show error on failure52            const success = Math.random() > 0.3; // 70% chance of success for demo53            54            if (success) {55                alert('Authentication successful! (This is a demo)');56                // window.location.href = '/dashboard'; // Redirect in real app57            } else {58                showError('Invalid credentials. Please try again.');59            }60        }, 1500);61    }62});