Download project 5/auth.js from thatsdevvvvv/Agile: direct link, hf CLI and curl.
- Browser
- Download file 3.78 kB
-
https://huggingface.co/datasets/thatsdevvvvv/Agile/resolve/main/project%205/auth.js
- Command line
-
hf download 'hf://datasets/thatsdevvvvv/Agile/project 5/auth.js'
-
curl -L -o auth.js https://huggingface.co/datasets/thatsdevvvvv/Agile/resolve/main/project%205/auth.js
3.78 kB
| // Simple authentication system for Agilisium Co-Lab | |
| const AUTH_KEY = 'onco.auth'; | |
| // Demo user data | |
| const DEMO_USER = { | |
| id: 'demo-001', | |
| name: 'Dev Karan', | |
| email: 'demo@agilisium.com', | |
| password: 'Demo@123', | |
| role: 'researcher', | |
| avatar: 'DK' | |
| }; | |
| // Auth helpers | |
| const auth = { | |
| // Login with email and password | |
| login(email, password, rememberMe = false) { | |
| return new Promise((resolve) => { | |
| // Simulate network delay | |
| setTimeout(() => { | |
| if (email === DEMO_USER.email && password === DEMO_USER.password) { | |
| const user = { | |
| id: DEMO_USER.id, | |
| name: DEMO_USER.name, | |
| email: DEMO_USER.email, | |
| role: DEMO_USER.role, | |
| avatar: DEMO_USER.avatar, | |
| token: 'token_' + Date.now(), | |
| expiresAt: Date.now() + (7 * 24 * 60 * 60 * 1000) // 7 days | |
| }; | |
| localStorage.setItem(AUTH_KEY, JSON.stringify(user)); | |
| resolve({ success: true, user }); | |
| } else { | |
| resolve({ success: false, error: 'Invalid email or password' }); | |
| } | |
| }, 500); | |
| }); | |
| }, | |
| // Quick demo login | |
| loginAsDemo() { | |
| return this.login(DEMO_USER.email, DEMO_USER.password, true); | |
| }, | |
| // Logout | |
| logout() { | |
| localStorage.removeItem(AUTH_KEY); | |
| this.showToast('You\'re signed out.', 'info'); | |
| }, | |
| // Get current user | |
| getUser() { | |
| try { | |
| const userData = localStorage.getItem(AUTH_KEY); | |
| if (!userData) return null; | |
| const user = JSON.parse(userData); | |
| // Check if session expired | |
| if (user.expiresAt && Date.now() > user.expiresAt) { | |
| this.logout(); | |
| return null; | |
| } | |
| return user; | |
| } catch (error) { | |
| return null; | |
| } | |
| }, | |
| // Check if authenticated | |
| isAuthenticated() { | |
| return this.getUser() !== null; | |
| }, | |
| // Show toast notification | |
| showToast(message, type = 'info') { | |
| // Remove existing toasts | |
| const existingToasts = document.querySelectorAll('.toast'); | |
| existingToasts.forEach(toast => toast.remove()); | |
| const toast = document.createElement('div'); | |
| toast.className = `toast toast-${type}`; | |
| toast.textContent = message; | |
| Object.assign(toast.style, { | |
| position: 'fixed', | |
| top: '20px', | |
| right: '20px', | |
| padding: '12px 20px', | |
| borderRadius: '8px', | |
| color: 'white', | |
| fontWeight: '500', | |
| zIndex: '10000', | |
| transform: 'translateX(100%)', | |
| transition: 'transform 0.3s ease', | |
| maxWidth: '300px', | |
| wordWrap: 'break-word', | |
| boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)' | |
| }); | |
| const colors = { | |
| success: '#10B981', | |
| error: '#EF4444', | |
| info: '#3B82F6' | |
| }; | |
| toast.style.backgroundColor = colors[type]; | |
| document.body.appendChild(toast); | |
| // Animate in | |
| setTimeout(() => { | |
| toast.style.transform = 'translateX(0)'; | |
| }, 100); | |
| // Remove after delay | |
| setTimeout(() => { | |
| toast.style.transform = 'translateX(100%)'; | |
| setTimeout(() => { | |
| if (toast.parentNode) { | |
| toast.parentNode.removeChild(toast); | |
| } | |
| }, 300); | |
| }, 3000); | |
| } | |
| }; | |
| // Make auth globally available | |
| window.auth = auth; | |