# Exam System - Complete User Guide ## โœ… System is Fully Operational! Your exam system now has complete user management and is ready to use. ## ๐Ÿš€ Quick Start ### 1. Access the Application Open your browser to: **http://localhost** ### 2. Register or Login **Option A: Use Test Account** - Username: `testuser` - Password: `test123` **Option B: Register New Account** 1. Go to: http://localhost/login 2. Click "Register here" 3. Fill in: - Username (unique) - Email (unique) - Password (min 6 chars) - Confirm password 4. Click "Register" 5. Auto-login after registration ### 3. Take an Exam 1. You'll see "Python Basics Exam" with status "available" 2. Click "Start Exam" 3. Answer questions (MCQ, True/False, Essay, Code) 4. System autosaves every 10 seconds 5. Watch the timer count down 6. Click "Submit Exam" when done 7. See success page ### 4. View Your History 1. Click "My History" in the header 2. See all your exam attempts 3. Click "View Results" to review answers 4. Click "Take Again" to retake any exam ## ๐Ÿ“‹ Features ### User Management - โœ… User registration with email verification - โœ… Secure login/logout - โœ… Session persistence - โœ… Password hashing ### Exam Taking - โœ… List all published exams - โœ… Exam status per user (available, in progress, finished) - โœ… Start new attempts - โœ… Resume in-progress attempts - โœ… Timer with auto-submit - โœ… Autosave every 10 seconds - โœ… 5 question types supported ### Exam History - โœ… View all your attempts per exam - โœ… See submission timestamps - โœ… View detailed results - โœ… Compare answers with correct ones - โœ… Retake any exam unlimited times ### Data Persistence - โœ… User database (SQLite with persistent volume) - โœ… Exam attempts in JSON files - โœ… Output bundles for each submission - โœ… Progress tracking per user ## ๐ŸŽฏ Complete Workflow ### As a New User ``` Register โ†’ Login โ†’ See Exams โ†’ Start Exam โ†’ Answer Questions โ†’ Submit โ†’ View Results โ†’ Check History โ†’ Retake if desired ``` ### Navigation **Header Menu:** - "Exam System" - Go home - "Login" - Login/register (if not logged in) - "[Username]" - Shows your username - "My History" - View exam history - "Logout" - Logout **Routes:** - `/` - Exam list - `/login` - Login/register - `/history` - Your exam history - `/exam/:id` - Take exam - `/result/:id` - View results - `/done/:id` - Submission confirmation ## ๐Ÿงช Testing the System ### Test Full Flow ```bash # 1. Check system is running docker-compose ps # Should show 3 containers: exam_server, exam_web, exam_nginx # 2. Open browser open http://localhost # 3. Register/Login # Use testuser/test123 or create new account # 4. Take exam # Click "Start Exam" on Python Basics # 5. Check data folders while taking exam ls -la data/attempts/1/python-basics-v1/ # 6. Submit and check output ls -la data/output/ # 7. View history # Click "My History" in header # 8. Retake # Click "Take Again" on Python Basics ``` ### API Testing ```bash # Login curl -c cookies.txt -X POST -H "Content-Type: application/json" \ -d '{"username":"testuser","password":"test123"}' \ http://localhost/api/auth/login/ # List exams curl -b cookies.txt http://localhost/api/exams/ # View history curl -b cookies.txt http://localhost/api/history/me/ ``` ## ๐Ÿ“Š Data Structure ### Database (Persistent) - Location: Docker volume `exam_system_db_data` - Contains: Users, sessions - Persists across restarts ### File System ``` data/ โ”œโ”€โ”€ input/ # Source exam JSON files โ”‚ โ””โ”€โ”€ python-basics-v1.json โ”œโ”€โ”€ attempts/{userId}/{examId}/ โ”‚ โ””โ”€โ”€ {attemptId}.json # Active attempts โ”œโ”€โ”€ output/ โ”‚ โ””โ”€โ”€ {examId}_{attemptId}.json # Final bundles โ”œโ”€โ”€ progress/ โ”‚ โ””โ”€โ”€ {userId}.json # Progress snapshots โ””โ”€โ”€ manifest.json # Exam registry ``` ### User IDs - Authenticated users: numeric IDs (1, 2, 3...) - Guest users: `guest_` prefix (for backward compatibility) ## ๐Ÿ”ง Administration ### Create Admin User ```bash docker-compose exec exam_server python manage.py createsuperuser ``` Access admin at: **http://localhost/admin** ### List All Users ```bash docker-compose exec exam_server python manage.py shell >>> from django.contrib.auth import get_user_model >>> User = get_user_model() >>> for u in User.objects.all(): >>> print(f"{u.id}: {u.username} - {u.email}") ``` ### Reset User's Exam ```bash # Via API (when logged in) curl -b cookies.txt -X POST http://localhost/api/exams/python-basics-v1/reset/ # Or manually delete files rm -rf data/attempts/1/python-basics-v1/* ``` ## ๐ŸŽจ Customization ### Add New Exam 1. Create exam JSON in `data/input/your-exam.json` 2. Follow format in `/docs/exam-format.md` 3. Update `data/manifest.json`: ```json { "exams": [ ..., { "examId": "your-exam", "path": "input/your-exam.json", "published": true, "version": "1.0.0" } ] } ``` 4. Refresh browser - new exam appears! ### Modify Exam Settings Edit exam JSON in `data/input/`: - Change duration - Add/remove questions - Adjust difficulty - Update metadata Changes take effect immediately (refresh browser). ## ๐Ÿ› Troubleshooting ### "Failed to load exams" **Fix:** ```bash # Restart backend docker-compose restart exam_server # Check logs docker-compose logs exam_server # Verify manifest exists cat data/manifest.json ``` ### "Can't login" **Fix:** ```bash # Verify user exists docker-compose exec exam_server python manage.py shell >>> from django.contrib.auth import get_user_model >>> User = get_user_model() >>> User.objects.all() # Create new user if needed >>> User.objects.create_user(username='user', email='user@example.com', password='pass123') ``` ### "History is empty" **Cause:** You haven't submitted any exams yet **Solution:** Take and submit an exam first ### "Can't retake" **Fix:** 1. Go to My History 2. Find the exam 3. Click "Take Again" 4. System resets and redirects to exam ### Database issues **Complete reset:** ```bash # Stop containers docker-compose down -v # This deletes the database volume # Then start fresh docker-compose up --build -d # Run migrations docker-compose exec exam_server python manage.py migrate # Create test user docker-compose exec exam_server python manage.py shell >>> from django.contrib.auth import get_user_model >>> User = get_user_model() >>> User.objects.create_user(username='testuser', email='test@example.com', password='test123') ``` ## ๐Ÿ“ˆ What's Different from Before ### Before (Guest Mode) - No user accounts - Session-based with `user_default` - Can't track individual users - Can't distinguish attempts ### Now (User System) - โœ… Individual user accounts - โœ… Secure authentication - โœ… Per-user exam history - โœ… Unlimited retakes - โœ… View all previous attempts - โœ… Compare results across attempts ## ๐ŸŽฏ Use Cases ### Student 1. Register account 2. Take assigned exams 3. View results 4. Retake to improve score 5. Track progress over time ### Instructor (Future) - View all student attempts - Grade essay questions - Export results - Analyze performance ### Self-Learner - Create own exams - Test knowledge repeatedly - Track improvement - Review past performance ## ๐Ÿ’พ Backup ### Backup User Database ```bash # Export database docker-compose exec exam_server python manage.py dumpdata > backup_users.json # Or backup the volume docker run --rm -v exam_system_db_data:/data -v $(pwd):/backup \ alpine tar czf /backup/db_backup.tar.gz -C /data . ``` ### Backup Exam Data ```bash tar -czf backup_data_$(date +%Y%m%d).tar.gz data/ ``` ## ๐Ÿ” Security - Passwords hashed with Django's PBKDF2 - Session cookies with CSRF protection - User ownership verification on all endpoints - Input validation on all forms ## ๐Ÿ“ฑ Mobile Support The UI is responsive and works on mobile browsers. ## โœจ Tips 1. **Use incognito window** to test multiple users simultaneously 2. **Check data folders** to see real-time file creation 3. **View browser console** (F12) to see API calls 4. **Check logs** if something doesn't work 5. **Restart containers** if behavior seems odd ## ๐ŸŽ‰ You're All Set! The system is complete and ready to use: - โœ… User registration/login - โœ… Exam taking with autosave - โœ… Submit functionality working - โœ… Exam history - โœ… View results - โœ… Unlimited retakes - โœ… All data persisted **Go to http://localhost and start learning!** ๐Ÿš€ --- **Need Help?** Check: - `SETUP.md` - Setup instructions - `TESTING.md` - Testing guide - `USER_SYSTEM_GUIDE.md` - User system details - `TROUBLESHOOTING.md` - Common issues - `/docs/` - Technical specifications