diff --git a/seed/badges.json b/seed/badges.json index 7ede664..be2ff30 100644 --- a/seed/badges.json +++ b/seed/badges.json @@ -1,9 +1,11 @@ { + "student1": [], "nate": [ "Perfect Round", "No Misses", "Accuracy Master", "Practice Streak", "Vocabulary Pro" - ] + ], + "admin1": [] } \ No newline at end of file diff --git a/seed/wordlists.json b/seed/wordlists.json index 0604ecb..dbd67e1 100644 --- a/seed/wordlists.json +++ b/seed/wordlists.json @@ -1,13 +1,13 @@ { - "student1": [], + "student1": [ + "apple", "banana", "cherry", "date", "elderberry", + "grape", "honeydew", "kiwi", "lemon", "mango" + ], "admin1": [ - "boy", - "bot", - "snot" + "administration", "education", "technology", "development", "programming" ], "nate": [ - "not", - "bot", - "snot" + "computer", "keyboard", "mouse", "screen", "printer", + "software", "hardware", "network", "database", "security" ] } \ No newline at end of file diff --git a/server.js b/server.js index 92a6a70..dc109f8 100644 --- a/server.js +++ b/server.js @@ -31,8 +31,55 @@ function ensureFileWithSeed(name, fallback = '{}') { fs.copyFileSync(seedPath, targetPath); console.log(`🌱 Seeded ${name} from seed/${name}`); } else { - fs.writeFileSync(targetPath, fallback); - console.log(`šŸ“„ Initialized ${name} with default`); + // Create default data for each file type + if (name === 'users.json') { + const defaultUsers = [ + { + "username": "admin1", + "hash": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8", // password + "role": "admin" + }, + { + "username": "nate", + "hash": "5a2a558c78d3717db731600c4f354fa1d9c84b556f108091a891f444f1bdec40", // nate123 + "role": "student" + }, + { + "username": "student1", + "hash": "8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92", // 123456 + "role": "student" + } + ]; + fs.writeFileSync(targetPath, JSON.stringify(defaultUsers, null, 2)); + console.log(`šŸ‘„ Created default users: admin1, nate, student1`); + } else if (name === 'wordlists.json') { + const defaultWordlists = { + "student1": [ + "apple", "banana", "cherry", "date", "elderberry", + "grape", "honeydew", "kiwi", "lemon", "mango" + ], + "admin1": [ + "administration", "education", "technology", "development", "programming" + ], + "nate": [ + "computer", "keyboard", "mouse", "screen", "printer", + "software", "hardware", "network", "database", "security" + ] + }; + fs.writeFileSync(targetPath, JSON.stringify(defaultWordlists, null, 2)); + console.log(`šŸ“ Created default word lists for all users`); + } else if (name === 'badges.json') { + const defaultBadges = { + "student1": [], + "nate": [], + "admin1": [] + }; + fs.writeFileSync(targetPath, JSON.stringify(defaultBadges, null, 2)); + console.log(`šŸ† Created default badge structure`); + } else { + fs.writeFileSync(targetPath, fallback); + console.log(`šŸ“„ Initialized ${name} with default`); + } } } } @@ -247,4 +294,32 @@ app.get('/getBadges', (req, res) => { // šŸš€ Server start app.listen(PORT, () => { console.log(`āœ… Server listening at http://localhost:${PORT}`); + + // Display available users for easy login + try { + const usersPath = path.join(DATA_DIR, files.users); + const users = readJsonSafe(usersPath, []); + console.log('\nšŸ‘„ Available Users:'); + console.log('ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”'); + console.log('│ Username │ Password │ Role │'); + console.log('ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤'); + + const userInfo = [ + { username: 'admin1', password: 'password', role: 'admin' }, + { username: 'nate', password: 'nate123', role: 'student' }, + { username: 'student1', password: '123456', role: 'student' } + ]; + + userInfo.forEach(user => { + const exists = users.find(u => u.username === user.username); + const status = exists ? 'āœ…' : 'āŒ'; + console.log(`│ ${user.username.padEnd(11)} │ ${user.password.padEnd(10)} │ ${user.role.padEnd(8)} │ ${status}`); + }); + + console.log('ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜'); + console.log('\nšŸ” Note: Change default passwords after first login!'); + console.log(`🌐 Access the app at: http://localhost:${PORT}\n`); + } catch (error) { + console.log('āš ļø Could not display user information'); + } }); \ No newline at end of file