Download js/modules/auth.js from farhadprag/deepsite-project-djsce: direct link, hf CLI and curl.
- Browser
- Download file 4.25 kB
-
https://huggingface.co/spaces/farhadprag/deepsite-project-djsce/resolve/main/js/modules/auth.js
- Command line
-
hf download hf://spaces/farhadprag/deepsite-project-djsce/js/modules/auth.js
-
curl -L -o auth.js https://huggingface.co/spaces/farhadprag/deepsite-project-djsce/resolve/main/js/modules/auth.js
4.25 kB
| // Authentication & Authorization Module | |
| // Handles user authentication, session management, and role-based access control | |
| export class AuthManager { | |
| constructor(app) { | |
| this.app = app; | |
| // Demo users - in production this would be API-based | |
| this.demoUsers = [ | |
| { | |
| id: 1, | |
| username: 'admin', | |
| password: 'Admin2024!', | |
| name: 'Max Mustermann', | |
| email: 'admin@firma.de', | |
| role: 'admin', | |
| branches: [1, 2, 3], | |
| branch: { id: 1, name: 'Hauptsitz', tenant: 'Hauptmandant' }, | |
| permissions: ['*'], | |
| twoFactorEnabled: false, | |
| lastLogin: null, | |
| createdAt: '2024-01-01' | |
| }, | |
| { | |
| id: 2, | |
| username: 'buchhaltung', | |
| password: 'Buchhaltung2024!', | |
| name: 'Erika Buchhalter', | |
| email: 'buchhaltung@firma.de', | |
| role: 'accountant', | |
| branches: [1], | |
| branch: { id: 1, name: 'Hauptsitz', tenant: 'Hauptmandant' }, | |
| permissions: ['accounting.read', 'accounting.write', 'documents.read', 'documents.write'], | |
| twoFactorEnabled: false, | |
| lastLogin: null, | |
| createdAt: '2024-01-15' | |
| }, | |
| { | |
| id: 3, | |
| username: 'manager', | |
| password: 'Manager2024!', | |
| name: 'Hans Geschäftsführer', | |
| email: 'gf@firma.de', | |
| role: 'manager', | |
| branches: [1, 2], | |
| branch: { id: 1, name: 'Hauptsitz', tenant: 'Hauptmandant' }, | |
| permissions: ['*'], | |
| twoFactorEnabled: true, | |
| lastLogin: null, | |
| createdAt: '2024-01-10' | |
| }, | |
| { | |
| id: 4, | |
| username: 'farhad', | |
| password: '200820Fa', | |
| name: 'Farhad', | |
| email: 'farhad@firma.de', | |
| role: 'manager', | |
| branches: [1, 2, 3], | |
| branch: { id: 1, name: 'Hauptsitz', tenant: 'Hauptmandant' }, | |
| permissions: ['accounting.read', 'accounting.write', 'documents.read', 'documents.write', 'calendar.*', 'communication.*', 'meetings.*'], | |
| twoFactorEnabled: false, | |
| lastLogin: null, | |
| createdAt: '2024-01-20' | |
| } | |
| ]; | |
| } | |
| async authenticate(username, password) { | |
| // Simulate API delay | |
| await new Promise(resolve => setTimeout(resolve, 500)); | |
| const user = this.demoUsers.find(u => u.username === username && u.password === password); | |
| if (!user) { | |
| return { | |
| success: false, | |
| message: 'Ungültige Anmeldedaten' | |
| }; | |
| } | |
| // Check if user is active | |
| if (user.isActive === false) { | |
| return { | |
| success: false, | |
| message: 'Benutzerkonto deaktiviert' | |
| }; | |
| } | |
| // Update last login | |
| user.lastLogin = new Date().toISOString(); | |
| // Return user data (without password) | |
| const { password: _, ...userData } = user; | |
| return { | |
| success: true, | |
| user: userData, | |
| token: this.generateToken(userData) | |
| }; | |
| } | |
| generateToken(user) { | |
| // Simulate JWT - in production this would be a real JWT | |
| return btoa(JSON.stringify({ | |
| userId: user.id, | |
| role: user.role, | |
| exp: Date.now() + (24 * 60 * 60 * 1000) // 24h | |
| })); | |
| } | |
| hasPermission(user, permission) { | |
| if (user.role === 'admin') return true; | |
| if (user.permissions.includes('*')) return true; | |
| return user.permissions.includes(permission); | |
| } | |
| canAccessBranch(user, branchId) { | |
| return user.branches.includes(branchId) || user.role === 'admin'; | |
| } | |
| async createUser(userData) { | |
| // In production: POST /api/users | |
| const newUser = { | |
| id: Date.now(), | |
| ...userData, | |
| createdAt: new Date().toISOString(), |