File size: 2,092 Bytes
cc44a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Global state management
const appState = {
    currentUser: null,
    isAuthenticated: false,
    role: null
};

// DOM ready function
document.addEventListener('DOMContentLoaded', () => {
    // Initialize components
    initAuthModal();
    
    // Check for saved session
    checkSavedSession();
});

function checkSavedSession() {
    const token = localStorage.getItem('edu_token');
    if (token) {
        // Validate token with backend in real implementation
        console.log('Found saved session token');
    }
}

function initAuthModal() {
    const modal = document.querySelector('custom-auth-modal');
    
    // Handle login form submission
    modal.shadowRoot.querySelector('#loginForm').addEventListener('submit', (e) => {
        e.preventDefault();
        const email = e.target.elements.email.value;
        const password = e.target.elements.password.value;
        const remember = e.target.elements.remember.checked;
        
        // Simulate login - replace with actual API call
        console.log(`Login attempt with ${email}`);
        setTimeout(() => {
            modal.hideModal();
            showToast('Login successful! Redirecting...', 'success');
        }, 1500);
    });
    
    // Handle password reset
    modal.shadowRoot.querySelector('#forgotForm').addEventListener('submit', (e) => {
        e.preventDefault();
        const email = e.target.elements.resetEmail.value;
        
        // Simulate reset request
        console.log(`Password reset requested for ${email}`);
        setTimeout(() => {
            modal.hideModal();
            showToast('Password reset link sent to your email', 'success');
        }, 1500);
    });
}

function showToast(message, type = 'info') {
    const toast = document.createElement('div');
    toast.className = `fixed bottom-4 right-4 px-6 py-3 rounded-lg shadow-lg text-white ${
        type === 'success' ? 'bg-green-500' : 'bg-blue-500'
    } fade-in`;
    toast.textContent = message;
    document.body.appendChild(toast);
    
    setTimeout(() => {
        toast.remove();
    }, 3000);
}