File size: 2,696 Bytes
7e6e3fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bda0cc
 
 
 
 
 
 
 
 
 
7e6e3fc
 
2bda0cc
7e6e3fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
document.addEventListener('DOMContentLoaded', function() {
    const pinInput = document.getElementById('pin');
    const unlockBtn = document.getElementById('unlockBtn');
    const fingerprintBtn = document.getElementById('fingerprintBtn');
    
    // Mock authentication functions
    async function checkPin() {
        const enteredPin = pinInput.value;
        
        if (!enteredPin || enteredPin.length < 4) {
            showToast('الرجاء إدخال رمز PIN مكون من 4 أرقام على الأقل', 'error');
            return;
        }
        
        // In a real app, you would check against stored hash
        showToast('جارٍ التحقق...', 'info');
        
        // Simulate API call
        setTimeout(() => {
            // Default PIN for demo: 1234
            if (enteredPin === '1234') {
                showToast('تم فتح القفل بنجاح!', 'success');
                // Redirect to home page
                setTimeout(() => {
                    window.location.href = 'home.html';
                }, 1000);
            } else {
                showToast('رمز PIN غير صحيح', 'error');
            }
        }, 1500);
    }
async function authenticateWithFingerprint() {
        showToast('جارٍ التحقق بالبصمة...', 'info');
        
        // Check if browser supports WebAuthn
        if (!window.PublicKeyCredential) {
            showToast('المتصفح لا يدعم المصادقة البيومترية', 'error');
            return;
        }
        
        // Simulate fingerprint auth
        setTimeout(() => {
            const isSuccess = Math.random() > 0.2; // 80% success rate for demo
            
            if (isSuccess) {
                showToast('تم المصادقة بنجاح!', 'success');
                setTimeout(() => {
                    window.location.href = 'home.html';
                }, 1000);
            } else {
                showToast('فشل المصادقة، حاول مرة أخرى', 'error');
            }
        }, 2000);
    }
    
    // Event listeners
    unlockBtn.addEventListener('click', checkPin);
    fingerprintBtn.addEventListener('click', authenticateWithFingerprint);
    
    // Allow submitting with Enter key
    pinInput.addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            checkPin();
        }
    });
});

function showToast(message, type) {
    const toast = document.createElement('custom-toast');
    toast.setAttribute('message', message);
    toast.setAttribute('type', type);
    document.body.appendChild(toast);
    
    setTimeout(() => {
        toast.remove();
    }, 3000);
}